openxml

OpenXML Custom column width not working

时间秒杀一切 提交于 2019-12-02 08:10:42
问题 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

Add a Caption to a Table or Figure in OpenXml

允我心安 提交于 2019-12-02 08:09:10
I'm trying to create this structure in OpenXml: <P> <Table /> <Caption>Table 1 - Some Text 1 </Caption> <Picture /> <Caption>Figure 1 - Some Text 2 </Caption> </P> In terms of code I have: var currentLine = new Paragraph(); currentLine.AppendChild(new Run(elem)); -> Where the elem is Table ... currentLine.AppendChild(new Run(elem2)); -> Where the elem2 is Drawing So I only miss the way to add captions, the same captions that I can do in MS Word References-> Insert Caption. Some information how to accomplish this would be very appreciated. Rui Use this: http://www.microsoft.com/en-us/download

Get particular page from Word document using Open XML SDK

北慕城南 提交于 2019-12-02 07:37:47
I want to convert each page of document into separate word document. So i need to get every page of document. I am not able to differentiate pages in open xml format. So please move me to right direction. using (WordprocessingDocument document = WordprocessingDocument.Open("test.docx", true)) { MainDocumentPart mainPart = document.MainDocumentPart; } Based on the documentation here , The client uses LastRenderedPageBreak toidentify pages when its last saved. and the xml for it is: <w:lastRenderedPageBreak/> I think you can use this to check and break pages unless the document you are working

Prevent tables from breaking over a page, if possible

白昼怎懂夜的黑 提交于 2019-12-02 06:34:50
I am using OpenXML to generate a word document which contains thousands of tables. Some of them span over the length of entire page, which is fine as there is no way to prevent that from happening, however, many of the tables contain only a few rows. Is there a property I can set to prevent these tables from breaking? It looks awful when a table with only two rows is split between two pages, or when a key row is the only one split on the previous page. I've spent a serious chunk of time navigating the MSDN pages with no luck... hopefully somebody has done this before. This is kind of a pain,

docx unbreakable words

你离开我真会死。 提交于 2019-12-02 06:29:47
问题 I'm trying to replace words in a docx file like described here: public static void SearchAndReplace(string document) { using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(document, true)) { string docText = null; using (StreamReader sr = new StreamReader(wordDoc.MainDocumentPart.GetStream())) { docText = sr.ReadToEnd(); } Regex regexText = new Regex("Hello world!"); docText = regexText.Replace(docText, "Hi Everyone!"); using (StreamWriter sw = new StreamWriter(wordDoc

Having trouble reading excel file with the OpenXML sdk

有些话、适合烂在心里 提交于 2019-12-02 05:58:04
I have a function that reads from an excel file and stores the results in a DataSet . I have another function that writes to an excel file. When I try to read from a regular human-generated excel file, the excel reading function returns a blank DataSet , but when I read from the excel file generated by the writing function, it works perfectly fine. The function then will not work on a regular generated excel file, even when I just copy and paste the contents of the function generated excel file. I finally tracked it down to this, but I have no idea where to go from here. Is there something

Does a good wrapper class and/or library for open xml Excel editing exist?

一曲冷凌霜 提交于 2019-12-02 05:32:24
I'm looking for a nice library for editing and/or generating Excel documents on our Windows server. I feel that the open xml sdk is probably the way to go, but to me the learning curve seems steep and our dev time is limited. I think that it just shouldn't be that difficult to edit an Excel document. I'm ready to reinvent the wheel, but thought it would be worthwhile to ask first whether there is a good project/library out there that wraps open xml and makes interacting with Excel easier. In this official MS tutorial, the code that retrieves the value of a cell is dozens of lines long. http:/

Replacing Text of Content Controls in OpenXML

白昼怎懂夜的黑 提交于 2019-12-02 04:54:09
问题 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=

Converting a <V:shape>/Embed to a w:drawing

被刻印的时光 ゝ 提交于 2019-12-02 04:48:05
I have a V:Shape that I am assuming has come from the conversion of a .Doc file to a .Docx file, but in the code I have written, I am wanting a DocumentFormat.OpenXml.Drawing.Pictures.Picture . Is there any way to programically convert to a Picture ? The snippet I'm using is: foreach (var item in value) { if (!item.Descendants<Picture>().Any()) //pictures are processed differently - they're an absolute s**t storm to code... { p.Append(item.CloneNode(true)); } else { p.Append(CreateImageRun(source, item, target, f)); } } public Run CreateImageRun(WordprocessingDocument sourceDoc, Run sourceRun,

Using open XML to create excel file

时光总嘲笑我的痴心妄想 提交于 2019-12-02 04:47:43
问题 I am trying to use Open XML to create a file but when trying to add just the first row of headers the file is being corrupted and I am unable to open, can anyone tell me what I am doing wrong here? using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create("C:\\testpdfs\\mytest.xlsx", SpreadsheetDocumentType.Workbook)) { // Add a WorkbookPart to the document. WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); // Add a