我正在使用 Docx.dll 制作一个 docx 生成器。到目前为止,我已经能够在文档中插入图像和文本。图像和段落未对齐。我需要将文本包装在图像中。我该怎么做?我在 google 中查找它并找到此链接 通过使用 Open XML SDK 2.0 在 Word 2007 中添加图像到文档。该代码也在工作并创建 word 文档,但 docx 文件未打开。
如何在 c# 中将文本“在文本前面”换行?
public static DocX CreateDocumentFile(List<CompanyInfo> info)
{
DocX document = DocX.Load(@"C:\Users\newton.sheikh\Documents\Visual Studio 2010\Projects\MSOffice\OpenXML\OpenXML\RetailWrite.docx");
foreach (var companies in info)
{
Formatting fm = new Formatting();
/*Inserting Image*/
Novacode.Image img = document.AddImage(@"C:\Users\newton.sheikh\Documents\Visual Studio 2010\Projects\MSOffice\OpenXML\OpenXML\logos\slime.png");
Novacode.Paragraph companyLogo = document.InsertParagraph("");
Picture pic1 = img.CreatePicture();
companyLogo.InsertPicture(pic1, 0);
Novacode.Paragraph CompanyName = document.InsertParagraph(companies.Name.ToString());
CompanyName.StyleName = "COMPANY";
Novacode.Paragraph CompanyPosition = document.InsertParagraph(companies.Position.ToString());
CompanyPosition.StyleName = "posit";
Novacode.Paragraph CompanyDescription = document.InsertParagraph(companies.Description.ToString());
CompanyDescription.StyleName = "descrip";
Novacode.Paragraph blankPara = document.InsertParagraph(" ");
Novacode.Paragraph blankPara2 = document.InsertParagraph(" ");
}
return document;
}