openxml-sdk

reading Excel Open XML is ignoring blank cells

北慕城南 提交于 2019-11-27 07:33:15
I am using the accepted solution here to convert an excel sheet into a datatable. This works fine if I have "perfect" data but if I have a blank cell in the middle of my data it seems to put the wrong data in each column. I think this is because in the below code: row.Descendants<Cell>().Count() is number of populated cells (not all columns) AND: GetCellValue(spreadSheetDocument, row.Descendants<Cell>().ElementAt(i)); seems to find the next populated cell (not necessarily what is in that index) so if the first column is empty and i call ElementAt(0), it returns the value in the second column.

Save modified WordprocessingDocument to new file

左心房为你撑大大i 提交于 2019-11-27 07:24:53
I'm attempting to open a Word document, change some text and then save the changes to a new document. I can get the first bit done using the code below but I can't figure out how to save the changes to a NEW document (specifying the path and file name). using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using DocumentFormat.OpenXml.Packaging; using System.IO; namespace WordTest { class Program { static void Main(string[] args) { string template = @"c:\data\hello.docx"; string documentText; using (WordprocessingDocument wordDoc =

OpenXML SDK: Make Excel recalculate formula

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:16:54
I update some cells of an Excel spreadsheet through the Microsoft Office OpenXML SDK 2.0. Changing the values makes all cells containing formula that depend on the changed cells invalid. However, due to the cached values Excel does not recalculate the formular, even if the user clicks on "Calculate now". What is the best way to invalidate all dependent cells of the whole workbook through the SDK? So far, I've found the following code snippet at http://cdonner.com/introduction-to-microsofts-open-xml-format-sdk-20-with-a-focus-on-excel-documents.htm : public static void ClearAllValuesInSheet

reading Excel Open XML is ignoring blank cells

瘦欲@ 提交于 2019-11-27 03:59:31
问题 I am using the accepted solution here to convert an excel sheet into a datatable. This works fine if I have "perfect" data but if I have a blank cell in the middle of my data it seems to put the wrong data in each column. I think this is because in the below code: row.Descendants<Cell>().Count() is number of populated cells (not all columns) AND: GetCellValue(spreadSheetDocument, row.Descendants<Cell>().ElementAt(i)); seems to find the next populated cell (not necessarily what is in that

OpenXML SDK having borders for cell

大兔子大兔子 提交于 2019-11-27 02:04:53
I have the following code that adds a cell with values and data-type for that cell in OpenXML SDK: Cell cell = InsertCellInWorksheet(column, row, worksheetPart); cell.CellValue = new CellValue(index.ToString()); cell.DataType = new EnumValue<CellValues>(CellValues.SharedString); For this cell, how do I add a border on each side? I also like to add a background color on the cell as well. I have the following but not sure how to add the border to the cell: Borders borders1 = new Borders() { Count = (UInt32Value)1U }; Border border1 = new Border(); LeftBorder leftBorder1 = new LeftBorder();

Applying % number format to a cell value using OpenXML

白昼怎懂夜的黑 提交于 2019-11-27 01:35:35
I want to apply the % (percentage) number format using open XML C# I have numeric value 3.6 that I want to display that number in excel as `3.6%. How do I achieve that? Selwyn WorkbookStylesPart sp = workbookPart.AddNewPart<WorkbookStylesPart>(); Create a stylesheet, sp.Stylesheet = new Stylesheet(); Create a numberingformat, sp.Stylesheet.NumberingFormats = new NumberingFormats(); // #.##% is also Excel style index 1 NumberingFormat nf2decimal = new NumberingFormat(); nf2decimal.NumberFormatId = UInt32Value.FromUInt32(3453); nf2decimal.FormatCode = StringValue.FromString("0.0%"); sp

Add HTML String to OpenXML (*.docx) Document

自古美人都是妖i 提交于 2019-11-27 00:52:00
问题 I am trying to use Microsoft's OpenXML 2.5 library to create a OpenXML document. Everything works great, until I try to insert an HTML string into my document. I have scoured the web and here is what I have come up with so far (snipped to just the portion I am having trouble with): Paragraph paragraph = new Paragraph(); Run run = new Run(); string altChunkId = "id1"; AlternativeFormatImportPart chunk = document.MainDocumentPart.AddAlternativeFormatImportPart( AlternativeFormatImportPartType

Optimal way to Read an Excel file (.xls/.xlsx)

老子叫甜甜 提交于 2019-11-27 00:12:34
I know that there are different ways to read an Excel file: Iterop Oledb Open Xml SDK Compatibility is not a question because the program will be executed in a controlled environment. My Requirement : Read a file to a DataTable / CUstom Entitie s (I don't know how to make dynamic properties/fields to an object[column names will be variating in an Excel file]) Use DataTable/Custom Entities to perform some operations using its data. Update DataTable with the results of the operations Write it back to excel file . Which would be simpler. Also if possible advice me on custom Entities (adding

Unable to use existing paragraph styles in Open Xml

北战南征 提交于 2019-11-26 22:26:26
问题 I'm working on an export of an HTML file to a Open XML wordfile. If in the HTML <h1> is used, I want to add a Heading1 style to that part. But somehow when I open the document in Microsoft Word 2010, the Style isn't applied. If I open the created document in Libre Office, there is some style applied. I also defined some styles myself, and if I use one of those styles, everything went well in Word and Libre Office. I opened the Open XML SDK 2.5 Productivity Tool for Microsoft Office and when I

What indicates an Office Open XML Cell contains a Date/Time value?

可紊 提交于 2019-11-26 19:46:33
I'm reading an .xlsx file using the Office Open XML SDK and am confused about reading Date/Time values. One of my spreadsheets has this markup (generated by Excel 2010) <x:row r="2" spans="1:22" xmlns:x="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <x:c r="A2" t="s"> <x:v>56</x:v> </x:c> <x:c r="B2" t="s"> <x:v>64</x:v> </x:c> . . . <x:c r="J2" s="9"> <x:v>17145</x:v> </x:c> Cell J2 has a date serial value in it and a style attribute s="9" . However, the Office Open XML Specification says that 9 corresponds to a followed hyperlink. This is a screen shot from page 4,999 of ECMA