private static List <Run> GetRuns(ReportCommon common) { List <Run> runs = new List <Run>(); if (common is ReportValue) { ReportValue reportvalue = common as ReportValue; Run r = new Run(); RunProperties rP = GetRunProperties(reportvalue, true); r.Append(rP); string text = reportvalue.Text; if (text.EndsWith(":")) { text = text + " "; } if (!text.EndsWith(": ")) { text = text + ": "; } Text t = CreateText(text); r.Append(t); runs.Add(r); r = new Run(); rP = GetRunProperties(reportvalue, false); r.Append(rP); r.Append(CreateText(reportvalue.Value)); runs.Add(r); } else if (common is ReportImage) { ReportImage reportImage = common as ReportImage; Run r = new Run(); RunProperties rP = GetRunProperties(reportImage); Drawing image = GetImageToBody(reportImage.RId, reportImage.Width * 600, reportImage.Height * 800); //Drawing image = new Drawing(); //image.Append(new A.Blip() { Embed = new StringValue(reportImage.RId) }); r.Append(rP); r.Append(image); runs.Add(r); } else if (common is ReportText) { Run r = new Run(); RunProperties rP = GetRunProperties(common); r.Append(rP); r.Append(CreateText(common.Text)); runs.Add(r); } return(runs); }
public static void CreateImageRid(ReportImage reportImage, MainDocumentPart objMainDocumentPart) { ImagePartType imagetype = ImagePartType.Jpeg; FileInfo newImg = new FileInfo(reportImage.Value); ImagePart newImgPart = objMainDocumentPart.AddImagePart(imagetype); //插入图片数据到Word里去. using (FileStream stream = newImg.OpenRead()) { newImgPart.FeedData(stream); } //Word返回给我们插入数据的标识符. reportImage.RId = objMainDocumentPart.GetIdOfPart(newImgPart); }
// Creates an header instance and adds its children. private static Header GeneratePageHeaderPart(ReportImage reportImge) { var runs = GetRuns(reportImge); Paragraph paragraph = new Paragraph(); paragraph.Append(GetParagraphProperties(reportImge)); foreach (var run in runs) { paragraph.Append(run); } paragraph.Append(new Run(new Text() { Text = "" })); Header header = new Header(); header.Append(paragraph); return(header); }
public static void AddHeader(MainDocumentPart mainDocPart, ReportImage reportImge) { // Delete the existing header parts. mainDocPart.DeleteParts(mainDocPart.HeaderParts); // Create a new header part and get its relationship id. HeaderPart newHeaderPart = mainDocPart.AddNewPart <HeaderPart>(); string rId = mainDocPart.GetIdOfPart(newHeaderPart); ImagePart imagepart = newHeaderPart.AddImagePart(ImagePartType.Jpeg); FileInfo newImg = new FileInfo(reportImge.Value); using (FileStream stream = newImg.OpenRead()) { imagepart.FeedData(stream); } string imageRID = newHeaderPart.GetIdOfPart(imagepart); reportImge.RId = imageRID; Header header = GeneratePageHeaderPart(reportImge); header.Save(newHeaderPart); foreach (SectionProperties sectProperties in mainDocPart.Document.Descendants <SectionProperties>()) { // Delete any existing references to headers. foreach (HeaderReference headerReference in sectProperties.Descendants <HeaderReference>()) { sectProperties.RemoveChild(headerReference); } HeaderReference newHeaderReference = new HeaderReference() { Id = rId, Type = HeaderFooterValues.Default }; sectProperties.Append(newHeaderReference); } header.Save(); }
private static IEnumerable <OpenXmlElement> GetParagraphProperties(ReportImage reportImge) { throw new NotImplementedException(); }