openxml

Insert OpenXmlElement after word bookmark in Open XML SDK

你。 提交于 2019-11-29 01:10:58
问题 I was able to access a bookmark in my word document using this code: var res = from bm in mainPart.Document.Body.Descendants<BookmarkStart>() where bm.Name == "BookmarkName" select bm; Now I want to insert a paragraph and a table after this bookmark. How do I do that? (example code would be appreciated) 回答1: Code Once you have the bookmark you can access its parent element and add the other items after it. using (WordprocessingDocument document = WordprocessingDocument.Open(@"C:\Path\filename

OpenXML libraries (alternatives to ClosedXML) [closed]

和自甴很熟 提交于 2019-11-29 01:09:33
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . What are some libraries that extend OpenXML (or add a kind of abstraction layer to OpenXML) similar to ClosedXML? I'm looking for a commercial or freeware tool with at least 1.0 version. Thank you in advance. 回答1: Open-Source: Have you looked at EPPlus? Slogan: Create advanced Excel 2007/2010 spreadsheets on the

Reading dates from OpenXml Excel files

风格不统一 提交于 2019-11-28 23:17:46
问题 I'm trying to read data from the .xlsx files using SharpZipLib to unpack it (in memory) and reading the inner xml files. Everything is fine but recognizing the dates - they're stored in julean format and I need to somehow recognize if a number is a date or only a number. In another topic (unfortunately it died and I need quick answer) I got to know some things from Mark Baker, but it's still not enough... "Excel stores dates as a float value... the integer part being the number of days since

Reading a date from xlsx using open xml sdk

最后都变了- 提交于 2019-11-28 20:19:46
I have a date in format "4/5/2011" (month/day/year) in a xlsx file in one of the cells. Im trying to parse the file and load those data in some classes. So far the part where I parse the cell looks like this: string cellValue = cell.InnerText; if (cell.DataType != null) { switch (cell.DataType.Value) { case CellValues.SharedString: // get string from shared string table cellValue = this.GetStringFromSharedStringTable(int.Parse(cellValue)); break; } } I hoped that date would be a cell.DataType. The truth is when parsing the cell with the date "4/5/2011", the value of cell.DataType is null and

Where can I find the XSDs of DOCX XML files?

烂漫一生 提交于 2019-11-28 14:27:15
I've created a docx file, unzipped it. Now I have: _rels (folder) docProps (folder) word (folder) [Content_Types].xml The content of [Content_Types].xml is: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"> <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/> <Default Extension="xml" ContentType="application/xml"/> <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/> <Override

How to access OpenXML content by page number?

▼魔方 西西 提交于 2019-11-28 13:44:22
Using OpenXML, can I read the document content by page number? wordDocument.MainDocumentPart.Document.Body gives content of full document. public void OpenWordprocessingDocumentReadonly() { string filepath = @"C:\...\test.docx"; // Open a WordprocessingDocument based on a filepath. using (WordprocessingDocument wordDocument = WordprocessingDocument.Open(filepath, false)) { // Assign a reference to the existing document body. Body body = wordDocument.MainDocumentPart.Document.Body; int pageCount = 0; if (wordDocument.ExtendedFilePropertiesPart.Properties.Pages.Text != null) { pageCount =

Excel File Password Protection with Open XML SDK

孤街醉人 提交于 2019-11-28 13:08:15
I am using Open XML SDK for creating excel files. I want to protect them with a password. Do you know anyway to protect excel file with a password by using Open XML SDK? I know "com" object way to protect them however, it is not suitable for my application. I need to protect file by using Open XML SDK or another way. Birol Capa Creating an excel password for protecting workbook or worksheet is possible by open xml. Following code samples are suggestions of Vincent ( http://spreadsheetlight.com/about/ ) ( https://stackoverflow.com/users/12984/vincent-tan ) (again I thank him a lot :) using

Importing Large XML file into SQL 2.5Gb

余生颓废 提交于 2019-11-28 12:51:58
问题 Hi I am trying to import a large XML file into a table on my sql server (2014) I have used the code below for smaller files and thought it would be ok as this is a once off, I kicked it off yesterday and the query was still running when I came into work today so this is obviously the wrong route. here is the code. CREATE TABLE files_index_bulk ( Id INT IDENTITY PRIMARY KEY, XMLData XML, LoadedDateTime DATETIME ) INSERT INTO files_index_bulk(XMLData, LoadedDateTime) SELECT CONVERT(XML,

Using OpenXML SDK to replace text on a docx file with a line break (newline)

一个人想着一个人 提交于 2019-11-28 12:44:41
I am trying to use C# to replace a specific string of text on an entire DOCX file with a line break (newline). The string of text that I am searching for could be in a paragraph or in a table in the file. I am currently using the code below to replace text. using (WordprocessingDocument doc = WordprocessingDocument.Open("yourdoc.docx", true)) { var body = doc.MainDocumentPart.Document.Body; foreach (var text in body.Descendants<Text>()) { if (text.Text.Contains("##Text1##")) { text.Text = text.Text.Replace("##Text1##", Environment.NewLine); } } } ISSUE: When I run this code, the output DOCX

OpenXML - Writing a date into Excel spreadsheet results in unreadable content

谁都会走 提交于 2019-11-28 10:51:43
I am using the following code to add a DateTime to a column in my spreadsheet: var dt = DateTime.Now; r.AppendChild<Cell>(new Cell() { CellValue = new CellValue(dt.ToOADate().ToString()), DataType = new EnumValue<CellValues>(CellValues.Date), StyleIndex = 1, CellReference = header[6] + index }); When I try to open the file in Excel 2010, I get the error Excel found unreadable content in file.xlsx All is fine if I comment out the line. I have referred to similar questions on StackOverflow, but they basically have the same code as I do. Dave Williams Late to the party as usual but I have to post