技术问题 | 快速查询常见技术问题及解答
|
028-81705109
|
|
微信扫一扫
|

在线编辑/WebAPI

  1. 简介
  2. Spire.Doc
  3. Spire.XLS
  4. Spire.PDF
  5. Spire.Presentation

作为e-iceblue 的客户,您可能想知道“它可以做什么”或者“怎么使用它”,为了回答大部分这种问题可以浏览每个产品页包含的功能描述或者参考相关的教程。下面列出的是一些您在使用中可能经常遇到的问题的答案。

如果您没有发现您问题的答案,请联系我们(support@e-iceblue.com),并提供我们下面的详细信息。

同时您可以加入我们的产品交流 QQ 群。

如何从Word文档中获取文本?
请使用document.GetText()方法。完整代码:
Document document = new Document();
document.LoadFromFile(@"..\..\test.docx");
using (StreamWriter sw = File.CreateText("output.txt"))
 {
 sw.Write(document.GetText());
 }
如何插入一张有指定宽高的图片?
您可以设置DocPicture的高度和宽度的属性来调整图像的大小。完整代码:
Document document = new Document();
document.LoadFromFile("sample.docx", FileFormat.Docx);
Image image = Image.FromFile("image.jpg");

//指定段落
Paragraph paragraph = document.Sections[0].Paragraphs[2];
DocPicture picture = paragraph.AppendPicture(image);

//调整图片大小
picture.Height = picture.Height * 0.8f;
picture.Width = picture.Width * 0.8f;
document.SaveToFile("result.docx", FileFormat.Docx);
怎样对齐word文档中的文本?
请设置段落的HorizontalAlignment属性来对齐文本。全部代码:
Document document = new Document();
document.LoadFromFile("sample.docx");

//左对齐
Paragraph paragraph1 = document.Sections[0].Paragraphs[0];
paragraph1.Format.HorizontalAlignment = HorizontalAlignment.Left;

//居中对齐
Paragraph paragraph2 = document.Sections[0].Paragraphs[1];
paragraph2.Format.HorizontalAlignment = HorizontalAlignment.Center;

//右对齐
Paragraph paragraph3 = document.Sections[0].Paragraphs[2];
paragraph3.Format.HorizontalAlignment = HorizontalAlignment.Right;
document.SaveToFile("result.docx");
如何更改现有书签里的文本?
您可以使用BookmarksNavigator找到指定的书签。 然后使用ReplaceBookmarkContent方法去替换书签中的文本。全部代码:
Document document = new Document();
document.LoadFromFile("sample.doc");
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.MoveToBookmark("mybookmark");

//替换书签中的内容
bookmarkNavigator.ReplaceBookmarkContent("new context", false);
document.SaveToFile("result.doc", FileFormat.Doc);
如何将Word转换成HTML?
您可以使用SaveToFile方法并指定文件格式为HTML将Word文档转换为html。全部代码:
Document document = new Document();
document.LoadFromFile("sample.doc");

//将Word保存为html
document.SaveToFile("result.html", FileFormat.Html);
document.Close();
如何将html转换成word文档?
请调用LoadFromFile方法加载html文件。 然后调用SaveToFile方法将html转换为word文档。 全部代码:
Document document = new Document();
document.LoadFromFile("sample.html", FileFormat.Html, XHTMLValidationType.None);

//将html保存为Word文档
document.SaveToFile("result.doc");
document.Close();
如何将word2007转换为word2003?
只需调用SaveToFile方法并指定的文件格式为doc即可。全部代码:
Document document = new Document("word2007.docx");
                    
//将word2007 转换为 word2003
document.SaveToFile("word2003.doc", FileFormat.Doc);
document.Close();
如何合并Word文件?
请使用Clone方法克隆一个章节。然后调用Add方法添加复制的章节到指定的文档。 全部代码:
Document document1 = new Document();
document1.LoadFromFile("merge1.docx");
Document document2 = new Document();
document2.LoadFromFile("merge2.docx");

//把document2中的章节添加到document1
 foreach (Section sec in document2.Sections)
{
    document1.Sections.Add(sec.Clone());
}
document1.SaveToFile("result.docx");
如何遍历Word文档中表的单元格?
Rows是表中行的集合,Cells是一行中单元格的集合。所以你可以使用两个循环遍历表的单元格。全部代码:
Document document = new Document();
document.LoadFromFile("sample.docx");
Spire.Doc.Interface.ITable table = document.Sections[0].Tables[0];
int i=0;

//遍历单元格
foreach (TableRow row in table.Rows)
{
    foreach (TableCell cell in row.Cells)
    {
        i++;
    }
}
如何用设置文字的阴影效果?
您只需要设置TextRange的IsShadow属性。 全部代码:
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
TextRange HText = paragraph.AppendText("this is a test!");

//设置IsShadow属性
HText.CharacterFormat.IsShadow = true;
HText.CharacterFormat.FontSize = 80;
document.SaveToFile("result.doc");
如何在Word中插入行号?
您需要设置该段的LineNumberingRestartMode,LineNumberingStep,LineNumberingStartValue属性插入行号。全部代码:
Document document = new Document();
Section section = document.AddSection();

//插入行号
section.PageSetup.LineNumberingRestartMode = LineNumberingRestartMode.RestartPage;
section.PageSetup.LineNumberingStep = 1;
section.PageSetup.LineNumberingStartValue = 1;
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText("As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers .NET applications.");
document.SaveToFile("result.doc");
如何设置文字环绕图片?
请设置图片的TextWrappingStyle和ShapeHorizontalAlignment属性。全部代码:
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
string str = "As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers.NET applications.As an independent Word .NET component, Spire.Doc for .NET doesn't need Microsoft Word to be installed on the machine. However, it can incorporate Microsoft Word document creation capabilities into any developers’.NET applications.";
paragraph.AppendText(str);
DocPicture picture = paragraph.AppendPicture(Image.FromFile("logo.png"));
picture.TextWrappingStyle = TextWrappingStyle.Tight;
picture.HorizontalAlignment = ShapeHorizontalAlignment.Center;
document.SaveToFile("result.doc");
如何编辑Word文档中现有的表?
首先获取表格,然后可以编辑单元格中的文本,还可以在表格中插入新行。全部代码:
Document doc = new Document("sample.docx");
Section section = doc.Sections[0];
ITable table = section.Tables[0];

//编辑单元格中的文本
TableCell cell1 = table.Rows[1].Cells[1];
Paragraph p1 = cell1.Paragraphs[0];
p1.Text = "abc";

TableCell cell2 = table.Rows[1].Cells[2];
Paragraph p2 = cell2.Paragraphs[0];
p2.Items.Clear();
p2.AppendText("def");

TableCell cell3 = table.Rows[1].Cells[3];
Paragraph p3 = cell3.Paragraphs[0];
(p3.Items[0] as TextRange).Text = "hij";

//插入新行
TableRow newRow = table.AddRow(true, true);
foreach (TableCell cell in newRow.Cells)
{
    cell.AddParagraph().AppendText("new row");
}
doc.SaveToFile("result.doc");
如何设置无下划线格式的超链接?
请将超链接的textRange的UndderlineStyle设置成None。全部代码:
Document document = new Document();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
Field hyperlink = paragraph.AppendHyperlink("www.e-iceblue.com", "www.e-iceblue.com", HyperlinkType.WebLink);
TextRange text = hyperlink.NextSibling.NextSibling as TextRange;
text.CharacterFormat.Bold = true;
text.CharacterFormat.UnderlineStyle = UnderlineStyle.None;
document.SaveToFile("result.doc");
如何将Word文档设置为只读?
请使用Protect方法并设置ProtectionType为AllowOnlyReading。全部代码:
Document document = new Document();
document.LoadFromFile("sample.docx");
document.Protect(ProtectionType.AllowOnlyReading);
document.SaveToFile("result.doc");
如何将图片添加到Excel?
请使用Add方法添加图片到Excel文件的工作表中。全部代码:
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
sheet.Pictures.Add(3, 2, "day.jpg");
workbook.SaveToFile("result.xlsx");
如何在Excel文件的工作表中插入新行?
请使用InsertRow方法在Excel文件的工作表中插入新行。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];

//在第三行插入新行
sheet.InsertRow(3);
workbook.SaveToFile("result.xlsx");
如何设置打印区域?
您可以设置工作表的PrintArea属性来实现。 全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];

//设置打印区域为B2到F8
sheet.PageSetup.PrintArea = "B2:F8";
workbook.SaveToFile("result.xlsx");
如何复制带格式的单元格?
Spire.XLS为您提供了Copy方法去复制带格式的单元格。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet1 = workbook.Worksheets[0];
Worksheet sheet3 = workbook.Worksheets[2];

//复制sheet1的单元格“B2”到sheet3的单元格“C6”
sheet1.Range[3, 2].Copy(sheet3.Range[6,3]);
workbook.SaveToFile("result.xlsx");
如何将Excel转换成PDF?
您只需要简单地加载文档,然后保存成PDF。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010);
workbook.SaveToFile("result.pdf", Spire.Xls.FileFormat.PDF);
怎样合并工作表中的单元格?
Spire.XLS为您提供了名为Merge的方法来合并XLS中的单元格。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];

//合并"B3"到"B4"的单元格
sheet.Range["B3:B4"].Merge();
workbook.SaveToFile("result.xlsx");
如何重新排列Excel中的工作表?
Spire.XLS为您提供了MoveWorksheet方法来重新排列excel中的工作表。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[3];

//将第4张工作表移到第1张工作表的位置
sheet.MoveWorksheet(0);
workbook.SaveToFile("result.xlsx");
如何删除excel工作表中的列?
请使用DeleteColumn方法来删除列。此方法即刻影响工作表的收集顺序。 全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[1];

//删除第2列
sheet.DeleteColumn(2);

//删除第4列
sheet.DeleteColumn(3);
workbook.SaveToFile("result.xlsx");
如何在Excel中设置指定范围的数字格式?
请使用NumberFormat属性去设置指定范围的数字格式。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");
Worksheet sheet = workbook.Worksheets[0];

//设置指定范围的数字格式
sheet.Range[2, 2, 6, 6].NumberFormat = "$#,##0.00";
sheet.Range["C3"].NumberValue = 3240.689;
sheet.Range["D4"].NumberValue = 5230.123;
workbook.SaveToFile("result.xlsx");
如何在单元格中添加公式?
只需设置单元格的Formula属性即可添加公式。全部代码:
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//添加IF公式到单元格J7中
string formula = @"=IF(H7>0,(IF(F7 > 0,(H7-F7)/F7,"""")),"""")";
worksheet.Range["J7"].Formula = formula;
worksheet.Range["F7"].NumberValue = 5;
worksheet.Range["H7"].NumberValue = 4;
workbook.SaveToFile("result.xlsx", ExcelVersion.Version2007);
如何合并多个Excel?
Spire.XLS为您提供了AddCopy方法来合并Excel文件。全部代码:
Workbook workbook = new Workbook();
workbook.LoadFromFile("sample1.xlsx");
Workbook workbookDest = new Workbook();
workbookDest.LoadFromFile("sample2.xlsx");
							
//将workbook中的单元格拷贝到workbookDest中
workbookDest.Worksheets.AddCopy(workbook.Worksheets);
workbookDest.SaveToFile("result.xlsx");
如何将HTML代码转换为PDF?
请在线程中使用LoadFromHTML加载html,然后保存为PDF。全部代码:
PdfDocument pdf = new PdfDocument();
PdfHtmlLayoutFormat htmlLayoutFormat = new PdfHtmlLayoutFormat();
htmlLayoutFormat.IsWaiting = false;
PdfPageSettings setting = new PdfPageSettings();
setting.Size = PdfPageSize.A4;
string htmlCode = File.ReadAllText("..\\..\\2.html");
Thread thread = new Thread(() =>
{ pdf.LoadFromHTML(htmlCode, false, setting, htmlLayoutFormat);});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();

pdf.SaveToFile("output.pdf");

另外,我们还有一个插件的方法转换html到PDF,参考文档:
Convert HTML string to PDF with New Plugin
如何在表的单元格中嵌入另一个表?
表格是一个更简单的网格。在网格中,您可以操纵每个单元格,为每个单元格设置不同的样式并嵌入另一个网格。所以您可以用网格来做这个工作。 全部代码:
PdfDocument document = new PdfDocument();
PdfPageBase page = document.Pages.Add(PdfPageSize.A4);

//新建一个网格
PdfGrid grid = new PdfGrid();
grid.Columns.Add(1);
grid.Columns[0].Width = page.Canvas.ClientSize.Width;
PdfGridRow row0 = grid.Rows.Add();
row0.Cells[0].Value = "This is the first row.";
row0.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
PdfGridRow row1 = grid.Rows.Add();
PdfLayoutResult result=grid.Draw(page, new PointF(0, 20));

PdfGrid grid2 = new PdfGrid();
grid2.Columns.Add(2);
PdfGridRow newrow = grid2.Rows.Add();
grid2.Columns[0].Width = grid.Columns[0].Width / 2;
grid2.Columns[1].Width = grid.Columns[0].Width / 2;
newrow.Cells[0].Value = "This is row two column one.";
newrow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
newrow.Cells[1].Value = "This is row two column two.";
newrow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
//将grid2嵌入到grid的row1的第一个单元格中
row1.Cells[0].Value = grid2;
result = grid2.Draw(page, new PointF(0, result.Bounds.Location.Y + result.Bounds.Height));
document.SaveToFile("result.pdf");
如何合并网格中的单元格?
请使用RowSpan或ColumnSpan属性去合并网格中的单元格。全部代码:
PdfDocument doc = new PdfDocument();
PdfPageBase page = doc.Pages.Add();

PdfGrid grid = new PdfGrid();
grid.Columns.Add(5);
float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
for (int i = 0; i < grid.Columns.Count; i++)
{
    grid.Columns[i].Width = width * 0.20f;
}
PdfGridRow row0 = grid.Rows.Add();
PdfGridRow row1 = grid.Rows.Add();

row0.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true);
row1.Style.Font = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Italic), true);

row0.Cells[0].Value = "Corporation";

//将row0的第一个单元格与下面的单元格合并
row0.Cells[0].RowSpan = 2;

row0.Cells[1].Value = "B&K Undersea Photo";
row0.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

//将row0的第二个单元格与右边的单元格合并
row0.Cells[1].ColumnSpan = 3;

row0.Cells[4].Value = "World";
row0.Cells[4].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
row0.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
row0.Cells[4].Style.BackgroundBrush = PdfBrushes.LightGreen;

row1.Cells[1].Value = "Diving International Unlimited";
row1.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
row1.Cells[1].ColumnSpan = 4;

grid.Draw(page, new PointF(0, 0));

doc.SaveToFile("result.pdf");
如何给PDF文件添加签名?
首先,使用PdfCertificate类创建一个证书实例,用于创建PdfSignature实例。然后设置PdfSignature实例的相关属性。全部代码:
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("sample.pdf");
PdfCertificate cert = new PdfCertificate("Demo.pfx", "e-iceblue");

//给每一页都添加一个signature
foreach (PdfPageBase page in doc.Pages)
{
    PdfSignature signature = new PdfSignature(page.Document, page, cert, "demo");
    signature.ContactInfo = "Harry";
    signature.Certificated = true;
    signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;
}

doc.SaveToFile("result.pdf");
如何将Word转换成HTML?
您可以使用SaveToFile方法并指定文件格式为HTML将Word文档转换为html。全部代码:
Document document = new Document();
document.LoadFromFile("sample.doc");

//将Word保存为html
document.SaveToFile("result.html", FileFormat.Html);
document.Close();
如何重新排列PDF页面顺序?
请使用ReArrange方法。该方法以int数组为参数。 int数组表示页面的新顺序。全部代码:
PdfDocument document = new PdfDocument();

//sample.pdf has four pages
document.LoadFromFile("sample.pdf");

//重新调整页面顺序
int[] range = new int[] { 0, 2, 1, 3 };
document.Pages.ReArrange(range);
document.SaveToFile("result.pdf");
如何添加图片水印?
请使用BackgroundImage方法,并且可以使用BackgroundRegion调整图片的大小以及位置。
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");
PdfPageBase page = pdf.Pages[0];
Image img = Image.FromFile("logo.png");
page.BackgroundImage = img;
page.BackgroundRegion = new RectangleF(300, 200, 80, 81);
pdf.SaveToFile("result.pdf");
如何在所有页面上重复页眉?
PdfDocumentTemplate中的内容将应用于PDF文件的每一页。你需要做的是创建一个方法,添加页眉到PdfDocumentTemplate中。然后页眉将会被添加到每个页面。全部代码:
static void Main(string[] args)
{
    PdfDocument doc = new PdfDocument();
    PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
    PdfMargins margin = new PdfMargins();
    margin.Top = unitCvtr.ConvertUnits(3.0f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
    margin.Bottom = margin.Top;
    margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
    margin.Right = margin.Left;

    //添加3页
    PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
    page = doc.Pages.Add(PdfPageSize.A4, margin);
    page = doc.Pages.Add(PdfPageSize.A4, margin);

    //应用模板
    SetDocumentTemplate(doc, PdfPageSize.A4, margin);
    doc.SaveToFile("result.pdf");

}
//method to add header to every page
private static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
{
    PdfPageTemplateElement leftSpace
        = new PdfPageTemplateElement(margin.Left, pageSize.Height);
    doc.Template.Left = leftSpace;

    PdfPageTemplateElement topSpace
        = new PdfPageTemplateElement(pageSize.Width, margin.Top);
    topSpace.Foreground = true;
    doc.Template.Top = topSpace;

    //draw header label
    PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
    PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
    String label = "Demo about Header Repeating";

    //set the header style
    SizeF size = font.MeasureString(label, format);
    float y = topSpace.Height - font.Height - 40;
    PdfPen pen = new PdfPen(Color.Black, 0.75f);
    topSpace.Graphics.SetTransparency(0.5f);
    topSpace.Graphics.DrawLine(pen, margin.Left - 30, y, pageSize.Width - margin.Right + 30, y);
    y = y - 1 - size.Height;
    topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format);

    PdfPageTemplateElement rightSpace
        = new PdfPageTemplateElement(margin.Right, pageSize.Height);
    doc.Template.Right = rightSpace;

    PdfPageTemplateElement bottomSpace
        = new PdfPageTemplateElement(pageSize.Width, margin.Bottom);
    bottomSpace.Foreground = true;
    doc.Template.Bottom = bottomSpace;
}
如何给PowerPoint文档添加密码保护?
请使用Encrypt方法给文档加密。全部代码:
Presentation presentation = new Presentation();
presentation.LoadFromFile("sample.pptx");
presentation.Encrypt("test");
presentation.SaveToFile("encrypt.pptx", FileFormat.Pptx2010);
如何转换PowerPoint文件到PDF?
只需要加载文件,然后保存成PDF即可。全部代码:
Presentation presentation = new Presentation();

//加载文件
presentation.LoadFromFile("ppt.ppt");

//把文件保存成PDF
presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
如何将幻灯片保存成图片?
请使用SaveAsImage方法将幻灯片保存到Image中,然后将Image对象保存成图片。全部代码:
Presentation ppt = new Presentation();
ppt.LoadFromFile(@"F:\testing\Sample.pptx");
for (int i = 0; i < ppt.Slides.Count; i++)
{

  //将幻灯片保存到Image中
  Image image = ppt.Slides[i].SaveAsImage();
  String fileName = String.Format("5614-img-{0}.png", i);

  //将image保存成文件
  image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);

}
如何设置文本框中文本的对齐方式?
请使用Alignment设置文本的对齐方式。全部代码:
Presentation presentation = new Presentation();

//添加一个shape
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 600, 400));

//设置shape里面第一段的对齐方式为左对齐
shape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
shape.Fill.FillType = FillFormatType.None;

//添加文本
shape.TextFrame.Text = "Demo about Alignment";
presentation.SaveToFile("alignment.pptx", FileFormat.Pptx2010);
如何提取PowerPoint中的文本?
请您使用TextParagraph的Text属性。全部代码:
StringBuilder sb = new StringBuilder();

for (int i = 0; i < ppt.Slides.Count;i++ )
       {
           for (int j = 0; j < ppt.Slides[i].Shapes.Count;j++ )
           {
               if (ppt.Slides[i].Shapes[j] is IAutoShape)
               {
                   IAutoShape shape=ppt.Slides[i].Shapes[j] as IAutoShape;
                   if (shape.TextFrame != null)
                   {
                       foreach (TextParagraph tp in shape.TextFrame.Paragraphs)
                       {
                           sb.Append(tp.Text + Environment.NewLine);
                       }
                   }

               }
           }
       }
如何用图片填充形状?
请使用PictureShape的Url属性。全部代码:
Presentation ppt = new Presentation();

IAutoShape shape = (IAutoShape)ppt.Slides[0].Shapes.AppendShape(ShapeType.DoubleWave, new RectangleF(100, 100, 400, 200));
string picUrl = @"C:\Users\Administrator\Desktop\image.jpg";
shape.Fill.FillType = FillFormatType.Picture;
shape.Fill.PictureFill.Picture.Url = picUrl;
shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
shape.ShapeStyle.LineColor.Color = Color.Transparent;
ppt.SaveToFile("shape.pptx", FileFormat.Pptx2010);