C#代碼實現(xiàn)在PowerPoint中創(chuàng)建編號或項目符號列表
列表是 PowerPoint 演示文稿中非常實用的工具,可以幫助你將信息清晰、簡明地呈現(xiàn)出來。無論是展示關(guān)鍵點、總結(jié)思路,還是突出重要內(nèi)容,合理使用列表都能提升幻燈片的可讀性、視覺效果和專業(yè)感。在本文中,我們將介紹如何使用 Spire.Presentation for .NET 在 C# 和 VB.NET 中創(chuàng)建 編號列表 和 項目符號列表。
安裝 Spire.Presentation for .NET
首先,需要將 Spire.Presentation for .NET 包中的 DLL 文件添加到你的 .NET 項目中作為引用。你可以通過下載 DLL 文件,也可以使用 NuGet 進行安裝。
PM> Install-Package Spire.Presentation
在 PowerPoint 中用 C# 和 VB.NET 創(chuàng)建編號列表
編號列表是在 PowerPoint 中,每一項前都帶有數(shù)字或數(shù)字序列的列表,通常按順序排列,從 1 開始依次遞增。編號列表常用于展示操作步驟、操作說明、排序信息或任何需要明確順序的內(nèi)容。
示例代碼如下:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace CreateNumberedList
{
internal class Program
{
static void Main(string[] args)
{
// 創(chuàng)建一個演示文稿對象
Presentation presentation = new Presentation();
// 獲取第一張幻燈片
ISlide slide = presentation.Slides[0];
// 向幻燈片添加一個形狀,并設(shè)置形狀樣式
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 300, 200));
shape.Fill.FillType = FillFormatType.None; // 無填充
shape.Line.FillType = FillFormatType.None; // 無邊框
// 向默認(rèn)段落添加文本
TextParagraph paragraph = shape.TextFrame.Paragraphs[0];
paragraph.Text = "所需的 Web 開發(fā)技能:";
paragraph.Alignment = TextAlignmentType.Left; // 左對齊
paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black; // 黑色字體
// 定義列表項
string[] listItems = new string[] {
" Command-line Unix",
" Vim",
" HTML",
" CSS",
" Python",
" JavaScript",
" SQL"
};
// 創(chuàng)建編號列表
foreach (string item in listItems)
{
TextParagraph textParagraph = new TextParagraph();
textParagraph.Text = item;
textParagraph.Alignment = TextAlignmentType.Left; // 左對齊
textParagraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
textParagraph.TextRanges[0].Fill.SolidColor.Color = Color.Black;
textParagraph.BulletType = TextBulletType.Numbered; // 設(shè)置為編號列表
textParagraph.BulletStyle = NumberedBulletStyle.BulletArabicPeriod; // 阿拉伯?dāng)?shù)字加點
shape.TextFrame.Paragraphs.Append(textParagraph); // 添加到形狀的文本框中
}
// 保存生成的演示文稿
presentation.SaveToFile("NumberedList.pptx", FileFormat.Pptx2013);
}
}
}在 PowerPoint 中用 C# 和 VB.NET 創(chuàng)建符號項目符號列表
符號項目符號列表是指在 PowerPoint 中,每一項前使用符號而非數(shù)字進行標(biāo)記的列表。它適用于展示 無特定順序的信息 或 要點集合,便于觀眾快速瀏覽和理解內(nèi)容,而不強調(diào)順序關(guān)系。
示例代碼如下:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace 創(chuàng)建符號項目符號列表
{
internal class Program
{
static void Main(string[] args)
{
// 創(chuàng)建一個 Presentation 對象
Presentation presentation = new Presentation();
// 獲取第一張幻燈片
ISlide slide = presentation.Slides[0];
// 在幻燈片上添加一個形狀,并設(shè)置形狀樣式
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 350, 200));
shape.Fill.FillType = FillFormatType.None; // 設(shè)置形狀填充為空
shape.Line.FillType = FillFormatType.None; // 設(shè)置形狀邊框為空
// 向默認(rèn)段落添加文本
TextParagraph paragraph = shape.TextFrame.Paragraphs[0];
paragraph.Text = "計算機科學(xué)課程:";
paragraph.Alignment = TextAlignmentType.Left; // 左對齊
paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black; // 設(shè)置字體顏色為黑色
// 定義列表項
string[] listItems = new string[] {
" 數(shù)據(jù)結(jié)構(gòu)",
" 算法",
" 計算機網(wǎng)絡(luò)",
" 操作系統(tǒng)",
" 計算理論",
" C語言編程",
" 計算機組成與體系結(jié)構(gòu)"
};
// 創(chuàng)建符號項目符號列表
foreach (string item in listItems)
{
TextParagraph textParagraph = new TextParagraph();
textParagraph.Text = item;
textParagraph.Alignment = TextAlignmentType.Left;
textParagraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
textParagraph.TextRanges[0].Fill.SolidColor.Color = Color.Black; // 字體顏色黑色
textParagraph.BulletType = TextBulletType.Symbol; // 設(shè)置為符號項目符號
shape.TextFrame.Paragraphs.Append(textParagraph);
}
// 保存生成的演示文稿
presentation.SaveToFile("符號項目符號列表.pptx", FileFormat.Pptx2013);
}
}
}在 PowerPoint 中使用 C# 和 VB.NET 創(chuàng)建圖片項目符號列表
在 PowerPoint 中,圖片項目符號列表用小圖標(biāo)或圖片代替?zhèn)鹘y(tǒng)的符號或數(shù)字項目符號。每一項內(nèi)容都用一張圖片來表示,為列表增加了視覺元素。當(dāng)你希望在列表中加入視覺提示,或者用相關(guān)圖標(biāo)或圖形表示各項內(nèi)容時,圖片項目符號列表尤其適用。
示例代碼如下:
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace 創(chuàng)建圖片項目符號列表
{
internal class Program
{
static void Main(string[] args)
{
// 創(chuàng)建一個演示文稿對象
Presentation presentation = new Presentation();
// 獲取第一張幻燈片
ISlide slide = presentation.Slides[0];
// 在幻燈片上添加一個形狀,并設(shè)置形狀樣式
IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 180));
shape.Fill.FillType = FillFormatType.None; // 設(shè)置形狀填充為空
shape.Line.FillType = FillFormatType.None; // 設(shè)置形狀邊框為空
// 向默認(rèn)段落添加文本
TextParagraph paragraph = shape.TextFrame.Paragraphs[0];
paragraph.Text = "項目任務(wù)待辦清單:";
paragraph.Alignment = TextAlignmentType.Left; // 左對齊
paragraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
paragraph.TextRanges[0].Fill.SolidColor.Color = Color.Black; // 設(shè)置字體顏色為黑色
// 定義列表項
string[] listItems = new string[] {
" 確定正在進行的項目和任務(wù)",
" 為任務(wù)分配負(fù)責(zé)人",
" 確定任務(wù)的優(yōu)先級",
" 跟蹤任務(wù)的進展?fàn)顟B(tài)",
" 完成任務(wù)后標(biāo)記為已完成"
};
// 創(chuàng)建圖片項目符號列表
foreach (string item in listItems)
{
TextParagraph textParagraph = new TextParagraph();
textParagraph.Text = item;
textParagraph.Alignment = TextAlignmentType.Left; // 左對齊
textParagraph.TextRanges[0].Fill.FillType = FillFormatType.Solid;
textParagraph.TextRanges[0].Fill.SolidColor.Color = Color.Black; // 字體顏色黑色
textParagraph.BulletType = TextBulletType.Picture; // 設(shè)置為圖片項目符號
// 添加圖片作為項目符號
IImageData image = presentation.Images.Append(Image.FromFile("icon.png"));
textParagraph.BulletPicture.EmbedImage = image;
// 將段落添加到形狀的文本框中
shape.TextFrame.Paragraphs.Append(textParagraph);
}
// 保存生成的演示文稿
presentation.SaveToFile("圖片項目符號列表.pptx", FileFormat.Pptx2013);
}
}
}到此這篇關(guān)于C#代碼實現(xiàn)在PowerPoint中創(chuàng)建編號或項目符號列表的文章就介紹到這了,更多相關(guān)C# PowerPoint創(chuàng)建編號和符號列表內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#如何通過匿名類直接使用訪問JSON數(shù)據(jù)詳解
這篇文章主要給大家介紹了關(guān)于C#如何通過匿名類直接使用訪問JSON數(shù)據(jù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起看看吧。2018-02-02

