openxml

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 - Writing a date into Excel spreadsheet results in unreadable content

余生长醉 提交于 2019-11-27 03:50:44
问题 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

OpenXML: Excel, extracting Cell text and Image/Picture data

吃可爱长大的小学妹 提交于 2019-11-27 03:41:37
问题 I am writing code to extract the cells and pictures/images in cells from an Excel doc into a database. With this code I can get the cell values that are not Pictures. However, the Cell object doesn't have a picture it in. Note that every row starts with an image. A1- Picture B1- Text C1- Text and so on. How do I get the image from the "A" column? WorkbookPart wbPart = document.WorkbookPart; var workSheet = wbPart.WorksheetParts.FirstOrDefault(); foreach (Row r in workSheet.Worksheet

What is the best way to store XML data in an Excel file

[亡魂溺海] 提交于 2019-11-27 02:55:28
问题 I am looking for a way to store XML data in an Excel file. The data should be completely hidden to the user, it should not be in a cell or comment, even hidden. Also, the data should be preserved when the user opens and then saves the file with Excel. I am not looking for a way to map cells to external XML data. The XML data should be inside the xlsx file. The data will be entered using a C# tool, not Excel itself. 回答1: The .xlsx file is actually just a compression archive (zip file) so if

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

Save Open XML as PDF

只愿长相守 提交于 2019-11-26 23:07:22
问题 As part of an investigation into enterprise level server side document generation I have come across Open XML. For those that have used this, how successful were you? Would you recommend it? Can you save the OpenXML to PDF directly or would I need to make use of a 3rd party component? If a 3rd Party component is required, which one did you use and which one would you recommend? Thanks Gineer 回答1: The nice thing about the Office OpenXML is that it's the language of Microsoft Office -- if you

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

How do you display a formatted Word Doc in HTML/PHP?

我怕爱的太早我们不能终老 提交于 2019-11-26 21:03:55
问题 What is the best way to display a formatted Word Doc in HTML/PHP? Here is the code I currently have but it doesn't format it: $word = new COM("word.application") or die ("Could not initialise MS Word object."); $word->Documents->Open(realpath("ACME.doc")); // Extract content. $content = (string) $word->ActiveDocument->Content; echo $content; $word->ActiveDocument->Close(false); $word->Quit(); $word = null; unset($word); 回答1: I know nothing about COM, but poking around the Word API docs on