1
我正在使用此處找到的WordprocessingDocument方法(Open XML)http://msdn.microsoft.com/en-us/library/bb497430.aspx將圖像添加到DOCX文件。獲取圖像細節以添加到DOCX
我可以添加圖片,但尺寸不正確。
MainDocumentPart mainPart = doc.MainDocumentPart;
ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
using (System.IO.FileStream stream = new System.IO.FileStream(fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
imagePart.FeedData(stream);
}
return AddImageToBody(doc, mainPart.GetIdOfPart(imagePart), fileName);
private static Drawing AddImageToBody(WordprocessingDocument wordDoc, string relationshipId, string filename)
{
long imageWidthEMU = 1900000;
long imageHeightEMU = 350000;
double imageWidthInInches = imageWidthEMU/914400.0;
double imageHeightInInches = imageHeightEMU/914400.0;
new DW.Extent();
//Define the reference of the image.
var element =
new Drawing(
new DW.Inline(
new DW.Extent() { Cx = imageWidthEMU, Cy = imageHeightEMU },
正如您所看到的,您可以手動指定尺寸(長度+寬度)。我無法動態獲取它們。你如何獲得正確的圖像大小以傳遞給此代碼?
謝謝。