openxml-sdk

What is the difference between CellValues.InlineString and CellValues.String in OpenXML?

两盒软妹~` 提交于 2019-11-29 02:26:08
问题 I am trying to write some code to generate an Excel spreadsheet and I am not sure what the difference between CellValues.InlineString and CellValues.String to insert text on the cells. Shall I use this: private void UpdateCellTextValue(Cell cell,string cellValue) { InlineString inlineString = new InlineString(); Text cellValueText = new Text { Text = cellValue }; inlineString.AppendChild(cellValueText); cell.DataType = CellValues.InlineString; cell.AppendChild(inlineString); } this private

create word document with Open XML

ⅰ亾dé卋堺 提交于 2019-11-29 02:04:45
I am creating a sample handler to generate simple Word document. This document will contains the text Hello world This is the code I use (C# .NET 3.5), I got the Word document created but there is no text in it, the size is 0. How can I fix it? (I use CopyStream method because CopyTo is available in .NET 4.0 and above only.) public class HandlerCreateDocx : IHttpHandler { public void ProcessRequest(HttpContext context) { using (MemoryStream mem = new MemoryStream()) { // Create Document using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(mem, WordprocessingDocumentType

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

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 =

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

How to split table to new PowerPoint slide when content flows off current slide using Open XML SDK 2.0

ぃ、小莉子 提交于 2019-11-28 10:25:40
I have a bunch of data that I need to export from a website to a PowerPoint presentation and have been using Open XML SDK 2.0 to perform this task. I have a PowerPoint presentation that I am putting through Open XML SDK 2.0 Productivity Tool to generate the template code that I can use to recreate the export. On one of those slides I have a table and the requirement is to add data to that table and break that table across multiple slides if the table exceeds the bottom of the slide. The approach I have taken is to determine the height of the table and if it exceeds the height of the slide,

Office Open XMl SDK Writing Numbers to Sheet

流过昼夜 提交于 2019-11-28 07:22:22
问题 I am trying wo write Numbers from a DataTable to an Datasheet - unfortunately, this does not work as expected, e. g. the DataSheet is corrupted. I am using the following code: private void AddDataToSheet(ExcelViewData data, SheetData sheetData) { var excelData = data.WriteableDataTable; //// this returns a datatable ////the numbers have a format like "8,1" "8,0" etc. for (int i = 0; i < excelData.Rows.Count; i++) { Row row = new Row(); //row.RowIndex = (UInt32)i; for (int c = 0; c < excelData

How to retrieve Tab names from excel sheet using OpenXML

前提是你 提交于 2019-11-28 06:58:24
I have a spreadsheet document that has 182 columns in it. I need to place the spreadsheet data into a data table, tab by tab, but i need to find out as I'm adding data from each tab, what is the tab name, and add the tab name to a column in the data table. This is how I set up the data table. I then loop in the workbook and drill down to the sheetData object and walk through each row and column, getting cell data. DataTable dt = new DataTable(); for (int i = 0; i <= col.GetUpperBound(0); i++) { try { dt.Columns.Add(new DataColumn(col[i].ToString(), typeof(string))); } catch (Exception e) {

How to add a comment to a cell in Excel 2007 using the Open XML SDK 2.0?

拟墨画扇 提交于 2019-11-28 05:51:03
问题 Has anyone ever had any luck figuring out how to add a comment to Excel using the Open XML SDK 2.0? I couldn't find any documentation on where to get started on this issue. 回答1: The below code will take the worksheet that you want to add comments to and then iterate over the commentsToAdd dictionary. The dictionary key is the cell reference (ie. A1) and the value is the comment text to be added. /// <summary> /// Adds all the comments defined in the commentsToAddDict dictionary to the

Add HTML String to OpenXML (*.docx) Document

大憨熊 提交于 2019-11-28 05:02:19
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.Html, altChunkId); chunk.FeedData(new MemoryStream(Encoding.UTF8.GetBytes(ioi.Text))); AltChunk altChunk