vgurunathaprasad
Forum Replies Created
Viewing 4 posts - 1 through 4 (of 4 total)
-
AuthorPosts
-
element.InnerText
will work
Hi Manu,
Can you give a snap shot of the innerXml of the paragraph or sample document, It will be easy to helpAugust 8, 2016 at 5:46 am in reply to: Locating and reading Embedded objects inside a ms-word table #3606Finally this is what I did,
string fileName = @"text1.docx"; using (var document = WordprocessingDocument.Open(fileName, true)) { var docPart = document.MainDocumentPart; var doc = docPart.Document; DocumentFormat.OpenXml.Wordprocessing.Table myTable = doc.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Table>().First(); foreach (TableRow row in myTable.Elements<TableRow>()) { foreach (TableCell cell in row.Elements<TableCell>()) { List<Paragraph> paras = cell.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>().ToList(); foreach (Paragraph p in paras) { string d = p.InnerXml; if (d.Contains("w:drawing")) { Console.WriteLine("Dude this is a image"); string[] st = Regex.Split(d,"r:embed=\""); st = Regex.Split(st[1],"\""); string rid = st[0]; var imageData = (ImagePart)docPart.GetPartById(rid); var stream = imageData.GetStream(); var byteStream = new byte[stream.Length]; int length = (int)stream.Length; stream.Read(byteStream, 0, length); string outputFilename = rid; // Write bytestream to disk using (var fileStream = new FileStream(outputFilename, FileMode.OpenOrCreate)) { fileStream.Write(byteStream, 0, length); } string result = ""; try { WebClient client = new WebClient(); client.Credentials = CredentialCache.DefaultCredentials; byte[] rep = client.UploadFile(@"http://localhost:8080/UploadFileServlet/upload", "POST", outputFilename); result = System.Text.Encoding.UTF8.GetString(rep); Console.WriteLine("------------>"+result); //string webData = client.DownloadString(@"http://localhost:8080/UploadFileServlet/upload"); //Console.WriteLine("######################"+webData); client.Dispose(); } catch (Exception err) { Console.WriteLine(err.Message); } Console.WriteLine(d); p.InnerXml = ""; Paragraph para = p.InsertBeforeSelf(new Paragraph()); Run run = para.AppendChild(new Run()); run.AppendChild(new Text("<img srv='"+result+"' alt='"+result+"' />")); } else { Console.Write("--n--"); } } } Console.WriteLine(); } Console.WriteLine(); doc.Save(); }
Thank you so n much …
and sorry for the late replyJuly 4, 2016 at 4:59 am in reply to: Locating and reading Embedded objects inside a ms-word table #3554Thank You So much sir, I will work on it and echo you back the results ASAP.
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)