openxml

.NET OpenXML performance issues

时光毁灭记忆、已成空白 提交于 2019-12-03 13:19:58
I am attempting to write out an Excel file from an ASP.NET web server using OpenXML. I have about 2100 records and its taking around 20-30 seconds to do this. Any way I can make it faster? Retrieving the 2100 rows from the db takes a fraction of a second. Not sure why manipulating them in memory would take any longer. Note: ExcelWriter is our custom class, but all its methods are directly from code in this link, http://msdn.microsoft.com/en-us/library/cc861607.aspx public static MemoryStream CreateThingReport(List<Thing> things, MemoryStream template) { SpreadsheetDocument spreadsheet =

Change font color in OpenXML word document (C#)

喜欢而已 提交于 2019-12-03 12:28:50
I've been searching for hours and I just can't seem to find a solid answer for this. I have an existing document with content controls that I need to edit the text in with external data. If the data for one of the controls is not present, then I need to replace the text with an appropriate notice and change the font color. I have the text entry and all that working just fine, the only part that won't seem to do its job is changing the font color. The current code I have doesn't give me any errors and is running through this method just fine, but when I look at the finished document its still

How can I modify the foreground and background color of an OpenXML TableCell?

自闭症网瘾萝莉.ら 提交于 2019-12-03 12:18:30
I'm creating the table cell as follows: private static TableCell GetHeaderCell(string cellText) { var tc = new TableCell(new Paragraph(new Run(new Text(cellText)))); return tc; } I want it to be blue with white text. I've tried the following, but it doesn't work; when I try to open the document I get an error that there is a problem with the contents: private static TableCell GetHeaderCell(string cellText) { var props = new TableCellProperties(); var solidFill = new SolidFill(); var rgbColorHex = new RgbColorModelHex() { Val = "FF0000" };//Red Background for Single TableCell. solidFill.Append

Generate a Word document (docx) using data from an XML file / Convert XML to a Word document based on a template

戏子无情 提交于 2019-12-03 11:17:30
问题 I have an XML file with the data that I need to be populated on a Word document. I need to find a way, to define a template which can be used as a base line to populate data from an XML file and create an output document. I believe there are two ways to do this. Create an XSLT file which will be the "template" and use this to generate Word documents using it in conjunction with the XML file. Use content controls in Word to create a template document and somehow map to an XML file. I just don

Simplify/ Clean up XML of a DOCX word document

*爱你&永不变心* 提交于 2019-12-03 08:44:28
问题 I have a Microsoft Word Document (docx) and I use Open XML SDK 2.0 Productivity Tool to generate C# code from it. I want to programmatically insert some database values to the document. For this I typed in simple text like [[place holder 1]] in the points where my program should replace the placeholders with its database values. Unfortunately the XML output is in some kind of mess. E.g. I have a table with two neighboring cells, which shouldn't distinguish apart from its placeholder. But one

how can I change the font open xml

点点圈 提交于 2019-12-03 07:46:28
问题 How can I change the font family of the document via OpenXml ? I tried some ways but, when I open the document, it's always in Calibri Follow my code, and what I tried. The Header Builder I think is useless to post private static void BuildDocument(string fileName, List<string> lista, string tipo) { using (var w = WordprocessingDocument.Create(fileName, WordprocessingDocumentType.Document)) { var mp = w.AddMainDocumentPart(); var d = new DocumentFormat.OpenXml.Wordprocessing.Document(); var b

How to programmatically insert comments into a Microsoft Word document?

我怕爱的太早我们不能终老 提交于 2019-12-03 06:14:33
Looking for a way to programmatically insert comments (using the comments feature in Word) into a specific location in a MS Word document. I would prefer an approach that is usable across recent versions of MS Word standard formats and implementable in a non-Windows environment (ideally using Python and/or Common Lisp). I have been looking at the OpenXML SDK but can't seem to find a solution there. Here is what I did: Create a simple document with word (i.e. a very small one) Add a comment in Word Save as docx. Use the zip module of python to access the archive (docx files are ZIP archives).

Open XML SDK 2.0 to get access to excel 2010 worksheet by name

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:00:54
I have an Excel 2010 spreadsheet that has 3 worksheets named Sheet1, Sheet2 and Sheet3. I'm trying to get a reference to a worksheet by name. I'm using the code: using (SpreadsheetDocument myWorkbook = SpreadsheetDocument.Open(FileName, true)) { //Access the main Workbook part, which contains all references WorkbookPart workbookPart = myWorkbook.WorkbookPart; WorksheetPart worksheetPart = workbookPart.WorksheetParts.Last(); // this gives me Sheet1 SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>(); } I am trying to get a reference to Sheet2, but I cannot find a way to do

Add a row to an existing table in a Word Document (open XML)

…衆ロ難τιáo~ 提交于 2019-12-03 06:00:49
问题 I need to open an existing Word document (.docx) with an existing table (with, for example, 3 columns) and add a new row to that table. Is there any way of doing this? I am using Open XML I am creating the table like this (for the first time): Table tbl = new Table(); // Set the style and width for the table. TableProperties tableProp = new TableProperties(); TableStyle tableStyle = new TableStyle() { Val = "TableGrid" }; // Make the table width 100% of the page width. TableWidth tableWidth =

Set custom BackgroundColor of a Excel sheet cell using epplus c#

妖精的绣舞 提交于 2019-12-03 05:21:51
问题 The problem: I am using EEPlus. I am stuck at applying a hex color code, e.g. #B7DEE8 , for a cell in my Excel sheet. I got the following (working) code: ws.Cells["A1:B1"].Style.Fill.PatternType = ExcelFillStyle.Solid; ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor(Color.Gray); But I need something like the following: ws.Cells["A1:B1"].Style.Fill.BackgroundColor.SetColor("#B7DEE8"); So my question is: is it possible to use hex color codes with EEPlus? If so, how can I do that? 回答1: Try