/// <summary> /// Add an image to the body by its stream /// </summary> /// <param name="image"></param> public void AddImage(Stream image) { ImagePart imagePart = _mainDocumentPart.AddImagePart("image/png"); imagePart.FeedData(image); AddImageToBody(_package, _mainDocumentPart.GetIdOfPart(imagePart)); }
private static ImagePart AddImagePart(MainDocumentPart mainPart, string extension) { ImagePart imagePart; switch (extension) { case ".png": imagePart = mainPart.AddImagePart(ImagePartType.Png); break; case ".jpeg": imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); break; case ".jpg": imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); break; case ".bmp": imagePart = mainPart.AddImagePart(ImagePartType.Bmp); break; default: imagePart = mainPart.AddImagePart(ImagePartType.Bmp); break; } return(imagePart); }
//word插入图片 public static void InsertAPicture(string document, string fileName) { string imgType = fileName.Split('.')[fileName.Split('.').Length - 1]; using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true)) { try { MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart; ImagePart imagePart = null; //判断图片的格式 if (imgType.ToUpper() == "JPEG" || imgType.ToUpper() == "JPE") { imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); } else if (imgType.ToUpper() == "PNG") { imagePart = mainPart.AddImagePart(ImagePartType.Png); } else if (imgType.ToUpper() == "GIF") { imagePart = mainPart.AddImagePart(ImagePartType.Gif); } else if (imgType.ToUpper() == "TIFF" || imgType.ToUpper() == "TIF") { imagePart = mainPart.AddImagePart(ImagePartType.Tiff); } if (imagePart != null) { if (File.Exists(fileName)) { using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart)); } else { Console.WriteLine("图片文件不存在"); } } else { Console.WriteLine("不支持的图片类型"); } } catch (Exception e) { Console.WriteLine("文档被占用!" + e); } } }
/// <summary> /// Download the image and try to find its format type. /// </summary> private HtmlImageInfo DownloadRemoteImage(string src) { Uri imageUri = new Uri(src, UriKind.RelativeOrAbsolute); Resource response; try { response = resourceLoader.FetchAsync(imageUri, CancellationToken.None).Result; if (response?.Content == null) { return(null); } } catch (Exception exc) { if (Logging.On) { Logging.PrintError(String.Format("Error fetching image from url: {0}", src), exc); } return(null); } HtmlImageInfo info = new HtmlImageInfo() { Source = src }; ImagePartType type; using (response) { // For requested url with no filename, we need to read the media mime type if provided response.Headers.TryGetValue("Content-Type", out string mime); if (!TryInspectMimeType(mime, out type) && !TryGuessTypeFromUri(imageUri, out type) && !TryGuessTypeFromStream(response.Content, out type)) { return(null); } var ipart = mainPart.AddImagePart(type); using (var outputStream = ipart.GetStream(FileMode.Create)) { response.Content.CopyTo(outputStream); outputStream.Seek(0L, SeekOrigin.Begin); info.Size = GetImageSize(outputStream); } info.ImagePartId = mainPart.GetIdOfPart(ipart); return(info); } }
//word doc add image, and convert image to text public static void DocxAddImage(MainDocumentPart mainPart, ref string text, List <WordImageDto> images) { if (images == null || images.Count == 0) { return; } foreach (var image in images) { //var imagePath = images[i]; //var width = Convert.ToDouble(images[i + 1]); //var height = Convert.ToDouble(images[i + 2]); //var tag = images[i + 3]; var imageService = new WordImageService(image.FilePath, image.Width, image.Height); var newText = ""; if (imageService.DataStream != null) { //TODO: how multiple images ?? var imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); imagePart.FeedData(imageService.DataStream); var imagePartId = mainPart.GetIdOfPart(imagePart); newText = GetImageRun(imagePartId, imageService).InnerXml; } text.Replace(image.Tag, newText); } }
/// <summary> /// 按书签插入图片 /// </summary> /// <param name="filePath"></param> /// <param name="picPath"></param> /// <param name="bm"></param> /// <param name="x">宽度厘米</param> /// <param name="y">高度厘米</param> /// <param name="type"></param> public static void InsertBMPicture(string filePath, string picPath, string bm, long x, long y, ImagePartType type) { using (WordprocessingDocument doc = WordprocessingDocument.Open(filePath, true)) { MainDocumentPart mainPart = doc.MainDocumentPart; BookmarkStart bmStart = findBookMarkStart(doc, bm); if (bmStart == null) { return; } ImagePart imagePart = mainPart.AddImagePart(type); using (FileStream stream = new FileStream(picPath, FileMode.Open)) { imagePart.FeedData(stream); } long cx = 360000L * x;//360000L = 1厘米 long cy = 360000L * y; Run r = AddImageToBody(doc, mainPart.GetIdOfPart(imagePart), cx, cy); bmStart.Parent.InsertAfter <Run>(r, bmStart); mainPart.Document.Save(); } }
public static void InsertAPicture(string fileName, string document, string bookmark) { OpenSettings openSettings = new OpenSettings(); // Add the MarkupCompatibilityProcessSettings openSettings.MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings( MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2007); // string document = @"E:\**项目\**文书\108.docx"; // document = @"F:\Project_Code\SVNProject\SDHS_SZCG_ZCCG\SZZF\SZZFWord\xcjckyyszj.docx"; using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(document, true)) { MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart), bookmark); } }
public static void ExportCaseToDoc(Case caseFile, string mapImagePath, string folderName) { using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(Path.Combine(folderName, string.Format("CaseReport-{0}.docx", caseFile.CaseNumber)), WordprocessingDocumentType.Document)) { //wordprocessingDocument.AddMainDocumentPart(); MainDocumentPart mainPart = wordprocessingDocument.AddMainDocumentPart(); mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); var para = body.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Paragraph()); var run = para.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Run()); run.AppendChild(new DocumentFormat.OpenXml.Wordprocessing.Text(string.Format("GPS Coordinate Report: Case #{0}", caseFile.CaseNumber))); ApplyStyleToParagraph(wordprocessingDocument, "Title", "Title", para); AddTable(body, caseFile.GPSCoordinates.Where(g => g.IncludedInMap).OrderBy(g => g.FileTime).ToList()); using (FileStream fs = new FileStream(mapImagePath, FileMode.Open, FileAccess.Read)) { ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); imagePart.FeedData(fs); AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart)); } //wordprocessingDocument.Save(); wordprocessingDocument.Close(); } }
private Run AddImage(WordprocessingDocument wordprocessingDocument, OpenXmlElement refChild, string imageBase64) { var bytes = Convert.FromBase64String(imageBase64.Split(',')[1]); var imagePath = Path.GetTempPath() + Guid.NewGuid().ToString() + ".png"; try { MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); File.WriteAllBytes(imagePath, bytes); // Carregando a imagem em imagePart using (FileStream stream = new FileStream(imagePath, FileMode.Open)) { imagePart.FeedData(stream); } return(AddImageToBody(wordprocessingDocument, refChild, mainPart.GetIdOfPart(imagePart), imagePath)); } finally { File.Delete(imagePath); } }
public static ImagePart AddImagePart(this MainDocumentPart mainDocPart, Stream stream) { var imagePart = mainDocPart.AddImagePart(ImagePartType.Jpeg); imagePart.FeedData(stream); return(imagePart); }
/// <summary> /// Adds an image part to the document and returns the part ID /// </summary> /// <param name="stream"></param> /// <param name="contentType"></param> /// <returns></returns> protected override string AddImagePart(Stream stream, string contentType) { var imagePart = MainDocumentPart.AddImagePart(ImagePartType.Png); imagePart.FeedData(stream); return(MainDocumentPart.GetIdOfPart(imagePart)); }
/* PseudoCode * Pull DocPartBody from Glossary document * Use DocPartBody to pull Drawing * Use Drawing to pull Blip which is where the image ID is stored * I think, IdPartPair is how to reference the document.xml.rels XML document * by searching for the id and returning the OpenXMLPart, ImagePart in this case * i.e. the Media folder. * */ public static void SimpleWordDoc_Create() { //string simpledocumentfullname = @"C:\Users\ajones\Documents\Automation\Prototypes\Sole Source Letter\Documents Generated\CB New Simple Document.docx" string simpledocumentfullnameHome = @"C:\Users\ajones\Documents\Visual Studio 2015\Operation Kyuzo\Prototypes and Study\Documents Generated\CB New Simple Document.docx"; //using (WordprocessingDocument NewSimpleDoc = WordprocessingDocument.Create(simpledocumentfullname, WordprocessingDocumentType.Document)) using (WordprocessingDocument NewSimpleDoc = WordprocessingDocument.Create(simpledocumentfullnameHome, WordprocessingDocumentType.Document)) { MainDocumentPart mdpNewSimpleDoc = NewSimpleDoc.AddMainDocumentPart(); mdpNewSimpleDoc.Document = new W.Document(new W.Body(new W.Paragraph(new W.Run(new W.Text())))); /* Adding image part now */ mdpNewSimpleDoc.AddImagePart(ImagePartType.Png, "rId7"); mdpNewSimpleDoc.AddImagePart(ImagePartType.Png, "rId8"); } Console.WriteLine("Done creating the document"); }
public static void CreateWordprocessingDocument(string filepath, List <Student> st) { String fileName = Constants.Locations.ImagesFolder + "/" + Constants.Locations.ImageFile; using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure and add some text. mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); foreach (var stu in st) { Paragraph para = body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); run.AppendChild(new Text("Hello , my name is " + stu.FirstName + " " + stu.LastName + "\n\n")); string imageFilePath = stu.FullPathUrl + "/" + Constants.Locations.ImageFile; var ImageBytes = FTP.DownloadFileBytes(imageFilePath); SaveBytesToFile(fileName, ImageBytes); ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart)); Paragraph PageBreakParagraph = new Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Break() { Type = BreakValues.Page })); body.Append(PageBreakParagraph); } // var styles = ExtractStylesPart(filepath, true); } }
public void InsertAutoText(string SignatureName) { const string NEW_DOCUMENT_NAME = "Sample AutoText Insert.docx"; string oldrelIDPic = ""; DocumentFormat.OpenXml.Drawing.Blip imgblip; using (WordprocessingDocument sampleDocument = WordprocessingDocument.Create(pathnewdoc + NEW_DOCUMENT_NAME, WordprocessingDocumentType.Document)) using (WordprocessingDocument wrdTemplate = WordprocessingDocument.Open(pathtemplatedoc + TEMPLATE_NAME, false)) { MainDocumentPart mdp = sampleDocument.AddMainDocumentPart(); mdp.Document = new Document(new Body()); GlossaryDocumentPart gDocPart = wrdTemplate.MainDocumentPart.GetPartsOfType <GlossaryDocumentPart>().FirstOrDefault(); if (gDocPart != null) { GlossaryDocument gDoc = gDocPart.GlossaryDocument; if (gDoc != null) { Console.WriteLine("AutoText Entries!"); foreach (DocPart entry in gDoc.DocParts) { if (entry.DocPartProperties.Category.Gallery.Val == DocPartGalleryValues.AutoText && entry.DocPartProperties.DocPartName.Val == SignatureName) { Console.WriteLine("Entry Name ==> {0}", entry.DocPartProperties.DocPartName.Val); Console.WriteLine(entry.DocPartBody.InnerXml); int paracount = entry.DocPartBody.Descendants <Paragraph>().Count(); Console.WriteLine("Count of paragraphs ==> {0}", paracount); foreach (Paragraph entrypara in entry.DocPartBody.Descendants <Paragraph>()) { // Let's get the relationship ID if it's there int PicCount = entrypara.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().Count(); if (PicCount > 0) { imgblip = entrypara.Descendants <DocumentFormat.OpenXml.Drawing.Blip>().FirstOrDefault(); oldrelIDPic = imgblip.Embed.Value; Console.WriteLine("Old Relationship ID ==> {0}", oldrelIDPic); imgblip.Embed.Value = "rId10"; Console.WriteLine(imgblip.Embed.Value); ImagePart newSigImg = mdp.AddImagePart(ImagePartType.Png, imgblip.Embed.Value); mdp.CreateRelationshipToPart(newSigImg, imgblip.Embed.Value); newSigImg.FeedData(gDocPart.GetPartById(oldrelIDPic).GetStream()); } mdp.Document.Body.AppendChild <Paragraph>(new Paragraph(entrypara.OuterXml)); } } } } } else { Console.WriteLine("No Glossary Document Part (AutoText Entries) found."); } } }
public void Reparent(MainDocumentPart documentPart) { ImagePart newImage = documentPart.AddImagePart(this._image.ContentType); newImage.FeedData(this._image.GetStream(FileMode.Open, FileAccess.Read)); String newId = documentPart.GetIdOfPart(newImage); this._id = newId; this._image = newImage; }
public static void InsertPicture(string fullPathToImageFile, WordprocessingDocument wordDoc) { MainDocumentPart mainPart = wordDoc.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fullPathToImageFile, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordDoc, mainPart.GetIdOfPart(imagePart)); }
private void InsertPicturePng(Stream imageStream, double scaleWidth, double scaleHeight) { MainDocumentPart mainPart = WordDoc.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Png); imagePart.FeedData(imageStream); AddImageToBody(mainPart.GetIdOfPart(imagePart), scaleWidth, scaleHeight); }
public void ApplyHeader(WordprocessingDocument doc) { MainDocumentPart mainDocPart = doc.MainDocumentPart; HeaderPart headerPart1 = mainDocPart.AddNewPart <HeaderPart>("r97"); //ImagePart imagePart = mainDocPart.AddNewPart<ImagePart>("image/jpeg", fileName); ImagePart imagePart = mainDocPart.AddImagePart(ImagePartType.Jpeg); string fileName = @"C:\multigestion\MultiFiscalia\Images\MultiFiscalia\Enviar.png"; //System.Web.HttpContext.Current.Server.MapPath(); using (FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { imagePart.FeedData(stream); } //var imagePart = doc.MainDocumentPart.AddNewPart<ImagePart>("image/jpeg", "rIdImagePart1"); //GenerateImagePart(imagePart); MemoryStream ms = new MemoryStream(); Header header1 = new Header(); Paragraph paragraph1 = new Paragraph() { }; Run run1 = new Run(); Text text1 = new Text(); text1.Text = "un texto cualquiera"; //run1.Append(ms.ToArray()); run1.Append(text1); paragraph1.Append(run1); header1.Append(paragraph1); headerPart1.Header = header1; SectionProperties sectionProperties1 = mainDocPart.Document.Body.Descendants <SectionProperties>().FirstOrDefault(); if (sectionProperties1 == null) { sectionProperties1 = new SectionProperties() { }; mainDocPart.Document.Body.Append(sectionProperties1); } HeaderReference headerReference1 = new HeaderReference() { Type = HeaderFooterValues.Default, Id = "r97" }; sectionProperties1.InsertAt(headerReference1, 0); //var element = "imagen"; //mainDocPart.Document.Body.PrependChild(new Paragraph(new Run(element))); }
public static ImagePart AgregarImagePart(MainDocumentPart mainPart, string imageFilename) { ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(imageFilename, FileMode.Open)) { imagePart.FeedData(stream); } return(imagePart); }
public void Modificar(string ruta, string carpeta, string nombreArchivo) { using (WordprocessingDocument documentoWord = WordprocessingDocument.Open(ruta, true)) { MainDocumentPart partePrincipal = documentoWord.MainDocumentPart; ImagenHeader(fileName, partePrincipal, documentoWord); ImagePart imagePart = partePrincipal.AddImagePart(ImagePartType.Jpeg); } }
private ImagePart CreateImagePart() { var imagePart = _mainDocumentPart.AddImagePart(ImagePartType.Png); using (var stream = new FileStream(_content, FileMode.Open)) { imagePart.FeedData(stream); } return(imagePart); }
public void InsertPicture(WordprocessingDocument wordprocessingDocument, string fileName) { MainDocumentPart mainPart = wordprocessingDocument.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart)); }
public Drawing GetPicture(WordprocessingDocument doc, string path) { MainDocumentPart mainPart = doc.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(path, FileMode.Open)) { imagePart.FeedData(stream); } return(AddImageToBody(doc, mainPart.GetIdOfPart(imagePart))); }
public void InsertAPicture(string fileName) { ImagePart imagePart = mainDocumentPart.AddImagePart(ImagePartType.Jpeg); FileStream stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite); imagePart.FeedData(stream); stream.Close(); Bitmap bm = new Bitmap(fileName); AddImageToBody(mainDocumentPart.GetIdOfPart(imagePart), (long)bm.Width * (long)((float)400000 / bm.HorizontalResolution), (long)bm.Height * (long)((float)400000 / bm.VerticalResolution)); }
public static void CreateWordprocessingDocument(List <string> HeaderData, List <List <string> > DataLines) { List <string> CsvData = new List <string>(); string filepath = $@"{Constants.Locations.DesktopPath}\{Constants.FTP.DocFile}"; // Create a document by supplying the filepath. using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document)) { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure and add some text. mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); Paragraph newPara = new Paragraph(new Run(new Text("This Document is created by Kashish Jhaveri."))); body.Append(newPara); ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); FTP.DownloadFile(Constants.FTP.ImageUrl, Constants.Locations.DesktopPath + "\\" + Constants.Locations.ImageFile); using (FileStream stream = new FileStream(Constants.Locations.DesktopPath + "\\" + Constants.Locations.ImageFile, FileMode.Open)) { imagePart.FeedData(stream); } AddImageToBody(wordDocument, mainPart.GetIdOfPart(imagePart)); for (int i = 0; i < DataLines.Count; i++) { newPara = new Paragraph(new Run (new Break() { Type = BreakValues.Page })); body.Append(newPara); CsvData = DataLines[i]; for (int j = 0; j < HeaderData.Count; j++) { Paragraph Para = new Paragraph(new Run(new Text($"\n {HeaderData[j]} : {CsvData[j]} \n"))); body.Append(Para); } } } }
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); }
/// <summary> /// Appends an Embedded Object into the specified Main Document /// </summary> /// <param name="mainDocumentPart">The MainDocument Part of your OpenXml Word Doc</param> /// <param name="fileInfo">The FileInfo object associated with the file being embedded</param> /// <param name="displayAsIcon">Whether or not to display the embedded file as an Icon (Otherwise it will display a snapshot of the file)</param> public static void AppendEmbeddedObject(MainDocumentPart mainDocumentPart, FileInfo fileInfo, bool displayAsIcon) { OpenXmlEmbeddedObject openXmlEmbeddedObject = new OpenXmlEmbeddedObject(fileInfo, displayAsIcon); if (!String.IsNullOrEmpty(openXmlEmbeddedObject.OleObjectBinaryData)) { using (Stream dataStream = new MemoryStream(Convert.FromBase64String(openXmlEmbeddedObject.OleObjectBinaryData))) { if (!String.IsNullOrEmpty(openXmlEmbeddedObject.OleImageBinaryData)) { using (Stream emfStream = new MemoryStream(Convert.FromBase64String(openXmlEmbeddedObject.OleImageBinaryData))) { string imagePartId = OpenXmlWordHelper.GetUniqueXmlItemID(); ImagePart imagePart = mainDocumentPart.AddImagePart(ImagePartType.Emf, imagePartId); if (emfStream != null) { imagePart.FeedData(emfStream); } string embeddedPackagePartId = OpenXmlWordHelper.GetUniqueXmlItemID(); if (dataStream != null) { if (openXmlEmbeddedObject.ObjectIsOfficeDocument) { EmbeddedPackagePart embeddedObjectPart = mainDocumentPart.AddNewPart <EmbeddedPackagePart>( openXmlEmbeddedObject.FileContentType, embeddedPackagePartId); embeddedObjectPart.FeedData(dataStream); } else { EmbeddedObjectPart embeddedObjectPart = mainDocumentPart.AddNewPart <EmbeddedObjectPart>( openXmlEmbeddedObject.FileContentType, embeddedPackagePartId); embeddedObjectPart.FeedData(dataStream); } } if (!displayAsIcon && !openXmlEmbeddedObject.ObjectIsPicture) { Paragraph attachmentHeader = OpenXmlWordHelper.CreateParagraph(JustificationValues.Left, OpenXmlWordHelper.ParagraphSpacing.AfterMedium, null, true, false, String.Format("Attachment: {0} (Double-Click to Open)", fileInfo.Name)); mainDocumentPart.Document.Body.Append(attachmentHeader); } Paragraph embeddedObjectParagraph = GetEmbeededObjectParagraph(openXmlEmbeddedObject.FileType, imagePartId, openXmlEmbeddedObject.OleImageStyle, embeddedPackagePartId); mainDocumentPart.Document.Body.Append(embeddedObjectParagraph); } } } } }
public void PlusImageInto(MainDocumentPart mainPart, Body body, string fileName) { ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } Paragraph imagePRG = this.MakePictureParagraph(mainPart.GetIdOfPart(imagePart)); //AddImageToBody(wordprocessingDocument, mainPart.GetIdOfPart(imagePart)); return; }
private void InsertPicture(MainDocumentPart mainPart, Paragraph paragraph, string fileBase64) { var bytes = Convert.FromBase64String(fileBase64); ImagePartType type = CheckImageType(bytes); ImagePart imagePart = mainPart.AddImagePart(type); using (MemoryStream stream = new MemoryStream(bytes)) { imagePart.FeedData(stream); } var element = CreateDrawing(mainPart.GetIdOfPart(imagePart)); var run = new Run(element); paragraph.AppendChild(run); }
/// <summary> /// 画图片 /// </summary> /// <param name="doc"></param> /// <param name="fileName"></param> /// <returns></returns> public static Drawing InsertAPicture(WordprocessingDocument doc, string fileName) { MainDocumentPart mainPart = doc.MainDocumentPart; ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(fileName, FileMode.Open)) { imagePart.FeedData(stream); } Drawing dw = AddImageToBody(mainPart.GetIdOfPart(imagePart)); return(dw); }