我正在使用dll创建方法,根据传递的参数生成创建段落的逻辑:
例如在我的C#代码上我有这个:
// document permission title
DocRun accessTypeTitle = new DocRun();
Run permissionTitle = accessTypeTitle.createParagraph("DOCUMENT ACCESS", PARAGRAPHCOLOR,FONTSIZETEXT,DEFAULTFONT);
我的方法在我的dll上做了逻辑:
public class DocRun
{
public Run createParagraph(String text, String colorVal, String fontSize,String font)
{
Run run = new Run() { RsidRunProperties = "00C53974" };
RunProperties runProperties = new RunProperties();
RunFonts runFonts = new RunFonts() { Ascii = font, HighAnsi = font, EastAsia = "Segoe UI", ComplexScript = font };
Color color = new Color() { Val = colorVal };
//Kern kern = new Kern() { Val = (UInt32Value)24U };
FontSize fontSize11 = new FontSize() { Val = fontSize };
FontSizeComplexScript fontSizeComplexScript11 = new FontSizeComplexScript() { Val = fontSize };
runProperties.Append(runFonts);
runProperties.Append(color);
//runProperties.Append(kern);
runProperties.Append(fontSize11);
runProperties.Append(fontSizeComplexScript11);
Text t = new Text(text)
{
Text = text,
Space = SpaceProcessingModeValues.Preserve
};
run.Append(runProperties);
run.Append(t);
return run;
}
}
}
在我退回运行后,我可以对图像和其他段落做同样的事情,然后将它们附加到文档中,如下所示:
var stream = new MemoryStream();
using (WordprocessingDocument doc = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document, true))
{
MainDocumentPart mainPart = doc.AddMainDocumentPart();
// Logo company construction
DocImage companyLogo = new DocImage();
Run imageLogo = companyLogo.imageCreator(mainPart,COMPANYLOGOPATH,COMPANYIMAGENAME,COMPANYLOGOWIDTH,COMPANYLOGOHEIGHT,COMPANYIMAGEALING);
DocImage titleShape = new DocImage();
Run imageShape = titleShape.imageCreator(mainPart, SHAPEIMAGEPATH, TITLESHAPEIMAGENAME, TITLESHAPEWIDTH, TITLESHAPEHEIGHT,SHAPEIMAGEALING);
DocImage clientImage = new DocImage();
Run clientLogo = titleShape.imageCreatorUrl(mainPart, SHAPEIMAGEPATH, TITLESHAPEIMAGENAME, TITLESHAPEWIDTHCLIENTLOGO, TITLESHAPEHEIGHTCLIENTLOGO, CLIENTIMAGEALIGN,clientLogoPath);
new Document(new Body()).Save(mainPart);
Body body = mainPart.Document.Body;
body.Append(new Paragraph(
new Run(imageLogo)));
body.Append(new Paragraph(
new Run(imageShape)));
body.Append(new Paragraph(
new Run(projectNameTxt)));
body.Append(new Paragraph(
new Run(clientLogo)));
body.Append(new Paragraph(
new Run(dateTxt)));
body.Append(new Paragraph(
new Run(permissionTitle)));
body.Append(new Paragraph(
new Run(permission)));
body.Append(new Paragraph(
new Run(disclaimerTitleTxt)));
body.Append(new Paragraph(
new Run(disclaimerDescriptionTxt)));
mainPart.Document.Save();
}
stream.Seek(0, SeekOrigin.Begin);
Directory.CreateDirectory(HostingEnvironment.MapPath(DOCUMENTSLOCATION));
System.IO.File.WriteAllBytes(HostingEnvironment.MapPath("~/Files/test5.docx"), stream.ToArray());
}
我的问题是文档生成的字体大小总是我在我创建的openXML dll上定义的实际大小的一半。
我将我传递的fontSize作为参数,并且dll上收到的字体大小是正确的,发生了什么?
谢谢你们,
答案 0 :(得分:0)
FontSize指定的值为半点测量值。因此,如果您需要11磅字体,则需要将值指定为22。
电子书"Open XML Explained" by Wouter Van Vugt中的第13页也记录了这一点。