Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active April 23, 2021 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/34752cb1d4a6250ab8b6b25ede15e94e to your computer and use it in GitHub Desktop.
Save aspose-com-gists/34752cb1d4a6250ab8b6b25ede15e94e to your computer and use it in GitHub Desktop.
NET的Aspose.Words-博客
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// 指定字体格式
Font font = builder.Font;
font.Size = 32;
font.Bold = true;
font.Color = System.Drawing.Color.Black;
font.Name = "Arial";
font.Underline = Underline.Single;
// 插入文字
builder.Writeln("This is the first page.");
builder.Writeln();
// 更改下一个元素的格式。
font.Underline = Underline.None;
font.Size = 10;
font.Color = System.Drawing.Color.Blue;
builder.Writeln("This following is a table");
// 插入表格
Table table = builder.StartTable();
// 插入一个单元格
builder.InsertCell();
// 使用固定的列宽。
table.AutoFit(AutoFitBehavior.AutoFitToContents);
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Write("This is row 1 cell 1");
// 插入一个单元格
builder.InsertCell();
builder.Write("This is row 1 cell 2");
builder.EndRow();
builder.InsertCell();
builder.Write("This is row 2 cell 1");
builder.InsertCell();
builder.Write("This is row 2 cell 2");
builder.EndRow();
builder.EndTable();
builder.Writeln();
// 插入图片
builder.InsertImage("image.png");
// 插入分页符
builder.InsertBreak(BreakType.PageBreak);
// 分页符后的所有元素都将插入下一页。
// 保存文件
doc.Save("Document.docx");
// 载入文件
Document doc = new Document("Document.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// 进入段落
var paragraph=doc.Sections[0].Body.Paragraphs[0].Runs[0];
paragraph.Text = "This is updated text";
// 保存文件
doc.Save("Document_updated.docx");
// 从磁盘加载文档。
Document doc = new Document("document.docx");
// 另存为纯文本
doc.Save("output.txt");
Document doc = new Document("word.docx");
// 提供对PDF17的PDFSaveOption合规性
PdfSaveOptions options = new PdfSaveOptions();
options.Compliance = PdfCompliance.Pdf17;
// 将Word转换为PDF
doc.Save("output.pdf", options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment