openxml

calculate cell values from formula programmatically in OpenXML sdk2

六眼飞鱼酱① 提交于 2019-12-02 04:36:45
问题 I'm using OpenXML SDK2.0 for excel calculations and stuck with 1 thing. Basically I'm populating an excel file with data from database and sending it to the user...that bit works fine. Now I want to get the calculated cell value after I'm putting a formula in it, but without opening the excel document... Is there a way to populate excel file with openxml sdk2.0 and get calculated values back straight away? Maybe someone has encountered similar problem or has a working solution ! Thanks:) 回答1:

Changing DataType of cell to Double

一曲冷凌霜 提交于 2019-12-02 04:15:15
问题 I'm using OpenXML to create Microsoft Excel file. I'm trying to insert a double type variable (Example : 4.987456789) into the Excel using Cell cell = new Cell() { CellReference = "A2", DataType = CellValues.String, CellValue = new CellValue(Convert.ToString(value)) }; But, when the cell is being made, it's in text form and Excel says "The number in this cell is formatted as text or preceded by an apostrophe." How can format the cell to insert double? Edit : Sorry, It's double? type and I

How to get list of shapes in SdtBlock element using Open XML SDK?

醉酒当歌 提交于 2019-12-02 04:15:09
问题 How can I get the list of shapes (textboxs) in an SdtBlock element using Open XML SDK? Regards. 回答1: In order to grab all the shapes in a WordProcessingDocument you can use linq to traverse all the descendants of the body: using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true)) { IEnumerable<DocumentFormat.OpenXml.Vml.Shape> shapes = wordDoc.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Vml.Shape>(); } 来源: https://stackoverflow.com/questions

OpenXML Custom column width not working

∥☆過路亽.° 提交于 2019-12-02 04:14:44
I'm trying to change the width of some excel columns. I've tried everything but I keep getting empty excel documents, my excel file works fine without this addition: Columns columns = new Columns(); columns.Append(new Column() { Min = 1, Max = 3, Width = 20, CustomWidth = true }); columns.Append(new Column() { Min = 4, Max = 4, Width = 30, CustomWidth = true }); wsPart.Worksheet.Append(columns); But as soon as I add this like this user suggested , I have to repair my excel file, and it will be empty. I get this error: "Replaced Part: /xl/worksheets/sheet.xml part with XML error. Load error.

Replacing Text of Content Controls in OpenXML

≯℡__Kan透↙ 提交于 2019-12-02 02:44:33
I have a word file that have multy Rich Text Content Control I want to change text of it. I Use this code . using (WordprocessingDocument theDoc = WordprocessingDocument.Open(docName, true)) { MainDocumentPart mainPart = theDoc.MainDocumentPart; foreach (SdtElement sdt in mainPart.Document.Descendants<SdtElement>()) { SdtAlias alias = sdt.Descendants<SdtAlias>().FirstOrDefault(); if (alias != null) { string sdtTitle = alias.Val.Value; var t = sdt.Descendants<Text>().FirstOrDefault(); t.Text="Atul works at Microsoft as a .NET consultant. As a consultant his job is to design, develop and deploy"

calculate cell values from formula programmatically in OpenXML sdk2

半城伤御伤魂 提交于 2019-12-02 00:28:01
I'm using OpenXML SDK2.0 for excel calculations and stuck with 1 thing. Basically I'm populating an excel file with data from database and sending it to the user...that bit works fine. Now I want to get the calculated cell value after I'm putting a formula in it, but without opening the excel document... Is there a way to populate excel file with openxml sdk2.0 and get calculated values back straight away? Maybe someone has encountered similar problem or has a working solution ! Thanks:) spreadSheet.WorkbookPart.Workbook.CalculationProperties.ForceFullCalculation = true; spreadSheet

How to Preserve string with formatting in OpenXML Paragraph, Run, Text?

点点圈 提交于 2019-12-01 23:26:32
问题 I am following this structure to add text from strings into OpenXML Runs, Which are part of a Word Document. The string has new line formatting and even paragraph indentions, but these all get stripped away when the text gets inserted into a run. How can I preserve it? Body body = wordprocessingDocument.MainDocumentPart.Document.Body; String txt = "Some formatted string! \r\nLook there should be a new line here!\r\n\r\nAndthere should be 2 new lines here!" // Add new text. Paragraph para =

Changing DataType of cell to Double

笑着哭i 提交于 2019-12-01 23:21:42
I'm using OpenXML to create Microsoft Excel file. I'm trying to insert a double type variable (Example : 4.987456789) into the Excel using Cell cell = new Cell() { CellReference = "A2", DataType = CellValues.String, CellValue = new CellValue(Convert.ToString(value)) }; But, when the cell is being made, it's in text form and Excel says "The number in this cell is formatted as text or preceded by an apostrophe." How can format the cell to insert double? Edit : Sorry, It's double? type and I follow this tutorial Using CellValues.Number works fine for me, for example : double? value = 4.9874567891

OpenXML replace specific customxml part of word document

孤街醉人 提交于 2019-12-01 22:41:33
I am using OpenXML SDK ver 2 to manipulate some word documents. The documents currently have custom xml parts and what I want to do is replace the xml for the parts specifically. I know I can do something like this to access the customxml parts of a document: Dim mainStream As New MemoryStream() Dim buffer As Byte() = File.ReadAllBytes(Server.MapPath("myfile.docx")) mainStream.Write(buffer, 0, buffer.Length) Try Using mainDocument As WordprocessingDocument = WordprocessingDocument.Open(mainStream, True) MainDocumentPart mainPart = mainDocument.MainDocumentPart; 'collection of custom xml parts

Set Rows to repeat at top when printing - Open XML and Excel

大兔子大兔子 提交于 2019-12-01 20:56:13
I am trying to get the first 4 rows of an xlsx file to repeat at the top of each page when printed. I am using the Open XML SDK to accomplish this. My file is being generated by the SSRS execution web service as a filestream. I then need to modify several layout and page settings (margins, page size, zoom, etc) before delivering the file to the user, as my users have very little Excel acumen. All other settings I need to tweak are working correctly, so I have stripped out all of that code from this example. When trying to set the repeating page headers using the code below, it executes with no