openxml

Word OpenXml Word Found Unreadable Content

…衆ロ難τιáo~ 提交于 2019-12-11 14:51:58
问题 We are trying to manipulate a word document to remove a paragraph based on certain conditions. But the word file produced always ends up being corrupted when we try to open it with the error: Word found unreadable content The below code corrupts the file but if we remove the line: Document document = mdp.Document; The the file is saved and opens without issue. Is there an obvious issue that I am missing? var readAllBytes = File.ReadAllBytes(@"C:\Original.docx"); using (var stream = new

How to set font size in empty cell of a Word table using the Open XML SDK?

心已入冬 提交于 2019-12-11 11:59:12
问题 I am creating a table in OpenXml with C# in a Word file. I used some code mentioned in this question to set the fontsize of the text in the cells. It works fine for the cells that contain text, but the empty cells seem to be given the normal style, and with that a bigger font size, which makes the row height bigger. Here is my sample code with a single row with a single cell, where the font size should be 9: TableRow tr = new TableRow(); TableCell tc = new TableCell(); Paragraph par = new

OOXML - Linq to Extract Word Tables With a Certain Caption

空扰寡人 提交于 2019-12-11 11:54:13
问题 I'm using the Open XML SDK 2.6 to try & update a Word Document. I can use the <w:tblCaption> element to identify a table. My question is, what Linq query do I need to use to get a reference to entire <w:tbl> structure, given a table with a certain <w:tblCaption> w:val attribute? DocumentFormat.OpenXml.Packaging.WordprocessingDocument doc = WordprocessingDocument.Open(@"D:\dev\openxml\table.docx", false); var tables = doc.MainDocumentPart.Document.Descendants<Table>().ToList(); //WHAT LINQ

How to access and replace text in certain paragraphs using OPENXML powertools case by case

牧云@^-^@ 提交于 2019-12-11 11:11:56
问题 I am trying to redact some word files using c# and openxml. I need to do controlled replace of the numbers with certain phrase. Each word file contains different amount of info. I want to use OPENXML powertools for this purspose. I used normal openxml method to replace but it very unreliable and gets random errors such as zero length error.I used regex replace and that seems to work but it replaces it through out the document which is highly undesirable. Here is some snippet of the code :

OpenXML Embedding PDF into Excel

岁酱吖の 提交于 2019-12-11 11:08:47
问题 I'm having trouble using OpenXML to embed files such as PDFs into Excel spreadsheets (Excel 2010). I want to be able to mimic the Insert>Object>Create From File and 'Display as Icon' behaviour that you can perform in Excel itself. I've created a spreadsheet with an example of the desired result and used it with the Reflector tool which is quite handy but just doesn't explain how the relationships work. Does anyone have a working solution to this or a link of where I might be able to find the

Finding implicit page break in word document using xml parsing

ⅰ亾dé卋堺 提交于 2019-12-11 10:22:17
问题 I need to extract the first page content of a word document. If I look at the openxml for a wordML document I could see things like: <w:lastRenderedPageBreak /> or it would seem <w:br w:type="page" /> <w:br w:type="page" /> occurs when user enters an hard page break. I don't understand in what all cases <w:lastRenderedPageBreak /> occurs. It occurs in some of the implict page break cases but not all. For example: I typed some text and then pressed enter several times and cursor goes to the

Change Sheet tab color of excel file using Open XML

∥☆過路亽.° 提交于 2019-12-11 10:06:43
问题 I want to change the sheet tab color of an excel Xlsx document. I am using the following code but it does not set the sheet color. I get object reference exception when I set the sheet tab color. public static string filepath = @"C:\Test\Book1.xlsx"; private static void ChangeSheetcolor() { try { using (SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(filepath, false)) { WorkbookPart workbookPart = spreadSheetDocument.WorkbookPart; IEnumerable<Sheet> sheets =

How to Join OPENXML data to my Inner Join Query?

与世无争的帅哥 提交于 2019-12-11 09:12:35
问题 OpenXML: DECLARE @idoc int DECLARE @doc varchar(1000) SET @doc = '<ROOT> <Employee EmployeeID = "1" EmpStatus = "Full Time"/> <Employee EmployeeID = "2" EmpStatus ="Part Time" /> </ROOT>' EXEC sp_xml_preparedocument @idoc OUTPUT, @doc SELECT * FROM OPENXML (@idoc, '/ROOT/Employee',1) WITH (EmployeeID varchar(10), EmpStatus varchar(20)) Results: EmployeeID EmpStatus 1 Full Time 2 Part Time Table query: SELECT hr.EmployeeID, hr.Title, c.FirstName,c.LastName FROM HumanResources.Employee hr WITH

Extract DOCX Comments

纵饮孤独 提交于 2019-12-11 08:55:07
问题 I'm a teacher. I want a list of all the students who commented on the essay I assigned, and what they said. The Drive API stuff was too challenging for me, but I figured I could download them as a zip and parse the XML. The comments are tagged in w:comment tags, with w:t for the comment text and . It should be easy, but XML (etree) is killing me. via the tutorial (and official Python docs): z = zipfile.ZipFile('test.docx') x = z.read('word/comments.xml') tree = etree.XML(x) Then I do this:

Working with OpenXML

纵饮孤独 提交于 2019-12-11 08:38:21
问题 I am passing XML to SQL Server stored procedure and trying it to store in #temp table. The stored procedure is given below: EXEC sp_xml_preparedocument @i OUTPUT ,@XMLDOC SELECT Id ,UserId ,ModifiedOn ,ModifiedBy ,ModifiedIp ,DetailId INTO #temp FROM OPENXML(@i, '/Root/Rec/Detail', 1) WITH ( id INT '../@Id' ,UserId INT '../@UserId' ,ModifiedOn DATETIME '../@ModifiedOn' ,ModifiedBy INT '../@ModifiedBy' ,ModifiedIp VARCHAR(15) '../@ModifiedIp' ,DetailId INT '@DetailId' ) EXEC sp_xml