twa*_*ron 5 c# asp.net openxml openxml-sdk
我正在使用 openXml SDK 创建一个简单的 word 文档。到目前为止它正在工作。现在如何将文件系统中的图像添加到此文档?我不在乎它在文档中的哪个位置,只是因为它就在那里。谢谢!这是我到目前为止所拥有的。
string fileName = "proposal"+dealerId +Guid.NewGuid().ToString()+".doc";
string filePath = @"C:\DWSApplicationFiles\Word\" + fileName;
using (WordprocessingDocument wordDoc = WordprocessingDocument.Create(filePath, WordprocessingDocumentType.Document, true))
{
MainDocumentPart mainPart = wordDoc.AddMainDocumentPart();
mainPart.Document = new Document();
//create the body
Body body = new Body();
DocumentFormat.OpenXml.Wordprocessing.Paragraph p = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
DocumentFormat.OpenXml.Wordprocessing.Run runParagraph = new DocumentFormat.OpenXml.Wordprocessing.Run();
DocumentFormat.OpenXml.Wordprocessing.Text text_paragraph = new DocumentFormat.OpenXml.Wordprocessing.Text("This is a test");
runParagraph.Append(text_paragraph);
p.Append(runParagraph);
body.Append(p);
mainPart.Document.Append(body);
mainPart.Document.Save();
}
Run Code Online (Sandbox Code Playgroud)
小智 0
此代码对我有用: http://msdn.microsoft.com/en-us/library/bb497430.aspx
您的代码将图像添加到您的 docx 包中,但为了在文档中看到它,您必须在 document.xml 中声明它,即将其链接到您的物理图像。这就是为什么您必须编写 msdn 链接中列出的长函数的原因。
我的问题是如何给图片添加效果(编辑、裁剪、背景去除)。如果您知道如何执行此操作,我将不胜感激您的帮助:)