openxml-sdk

How to get MS Word total pages count using Open XML SDK?

半腔热情 提交于 2019-12-11 03:05:04
问题 I am using below code to get the page count but it is not giving actual page count(PFA). What is the better way to get the total pages count? var pageCount = doc.ExtendedFilePropertiesPart.Properties.Pages.Text.Trim(); Note: We cannot use the Office Primary Interop Assemblies in my Azure web app service Thanks in advance. 回答1: In theory, the following property can return that information from the Word Open XML file, using the Open XML SDK: int pageCount = (int) document

Open XML change fontsize of table

做~自己de王妃 提交于 2019-12-11 02:49:50
问题 for (var i = 0; i <= data.GetUpperBound(0); i++) { var tr = new DocumentFormat.OpenXml.Wordprocessing.TableRow(); for (var j = 0; j <= data.GetUpperBound(1); j++) { var tc = new DocumentFormat.OpenXml.Wordprocessing.TableCell(); tc.Append(new DocumentFormat.OpenXml.Wordprocessing.Paragraph(new DocumentFormat.OpenXml.Wordprocessing.Run(new DocumentFormat.OpenXml.Wordprocessing.Text(data[i, j])))); tr.Append(tc); } table.Append(tr); } I want to change fontsize in table cell. Can you help me

OpenXML - Protect all sheets

◇◆丶佛笑我妖孽 提交于 2019-12-11 02:48:28
问题 I'm able to protect just one sheet, but when I try to protect all sheets in my Excel Documents I get an error while trying to append the SheetProtection. If I've understood correctly, I must append SheetProtection after the SheetData. Here is my code: SheetProtectiond sheetProtection = new SheetProtection { Sheet = true, Objects = true, Scenarios = true, Password = GetSheetPassword(workbookPassword) }; foreach(Sheet sheet in sheet) { WorksheetPart worksheetPart = GetWorksheetPartBySheetID(m

Merge cells in Excel using “Openxml writer”

半世苍凉 提交于 2019-12-10 22:45:33
问题 I want to merge cells in excel by using SAX approach with openxmlwriter. I have used these approach instead of DOM approach is to write thousands of records to excel. 回答1: I am sharing piece of code which may help others to write code to merge cells using OpenXmlWriter (OpenXml SAX) // OpenXMLWriter to write large data to excel to avoid System.OutOfMemoryException OpenXmlWriter oxw = OpenXmlWriter.Create(wsPart); oxw.WriteStartElement(new Worksheet()); // Excel column style oxw

Read excel sheet data in columns using OpenXML

十年热恋 提交于 2019-12-10 21:57:40
问题 Is there a way to read the excel sheet column wise rather than in rows using OpenXML-SDK & C#. I have already tried using EPPlus package, but faced some problems because my application also uses ".xslm" files which are not supported by EPPlus. So, I need a solution in OpenXML for reading data in columns. If anyone has a example, that will help. Thanks Sri 回答1: WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.First().Id); // Get the cells in the specified

Replacing in inner Text in open xml element?

坚强是说给别人听的谎言 提交于 2019-12-10 20:42:38
问题 I'm using open xml SDK 2.0 and i'm kind off new to this. I have actually created a quickpart (containg content control) in my word 2007 document named "hello.docx". Now I need to copy the quickpart into the other location of the same document named "hello.docx". I was very thank full for this post http://www.techques.com/question/1-3448297/Replacing-Content-Controls-in-OpenXML and same thing is posted on stack overflow forum for which i was very thank full :)...This post just deletes the

Replace text holder with image in OpenXML

蹲街弑〆低调 提交于 2019-12-10 20:22:07
问题 Below I have code that inserts an image at the end of a document in word using OpenXML. What I need to do is try and find and item called [Image Holder] within the document and replace that with the image I'm passing over. Here is the current code that adds it to the end of a document var element = new Drawing( new DW.Inline( new DW.Extent() { Cx = 990000L, Cy = 792000L }, new DW.EffectExtent() { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }, new DW.DocProperties() { Id =

How do I add an XML Map programmatically to an Excel 2010 Spreadsheet?

给你一囗甜甜゛ 提交于 2019-12-10 20:10:53
问题 I have a basic XML file, which I need to add as an XML Map to an Excel 2010 Worksheet. How do I do this programmatically? I would prefer a solution which uses Microsoft OpenXML SDK. 回答1: You will need to add a CustomXmlMappingsPart to your WorkbookPart and populate it with the schema for your XML. Then you will need to add a ConnectionsPart that is linked to your xml file. The below xml lives on my desktop in the file note.xml: <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading

Can I set auto-width on an Open XML SDK-generated spreadsheet without calculating the individual widths?

孤街浪徒 提交于 2019-12-10 17:16:14
问题 I'm working on creating an Excel file from a large set of data by using the Open XML SDK. I've finally managed to get a functional Columns node, which specifies all of the columns which will actually be used in the file. There is a "BestFit" property that can be set to true, but this apparently does not do anything. Is there a way to automatically set these columns to "best fit", so that when someone opens this file, they're already sized to the correct amount? Or am I forced to calculate how

Word OpenXML . Traversing OpenXmlElements between bookmarks

拈花ヽ惹草 提交于 2019-12-10 17:14:09
问题 I need to traverse nodes between a bookmark start and a bookmark end tag. The problem appears to break down into a tree traversal but I am having trouble pinning down the correct algorithm. The bookmark start and end elements are non-composite nodes (no children) and may appear at an arbitrary depth in the tree. Bookmark start are also not guaranteed to be a at the same depth. If you draw the tree structure for the document I would want to examine all nodes between the start and end bookmark.