openxml-sdk

How to Create/Open Excel files using OpenXml with C#

廉价感情. 提交于 2019-12-12 00:40:57
问题 I have a console application in which we are creating xlsx files using OPENXML, we are able to create xlsx file & save it into specific folder in application. But Now we want to show that file as a Save/Open dialog pop up. Then we can able to specify a particular path to save/ to open the existing files. I am new to this OpenXml, Can anyone please help me on this to proceed further? How can I acheive this? Do we have any built-in DLL for this? Thanks. 回答1: se the Save file dialog. It will

Reading data from Excel cells using OpenXML SDK 2.0

◇◆丶佛笑我妖孽 提交于 2019-12-11 18:32:54
问题 I'm trying to get value from Excel cells in this way: SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open(filePath, true); WorksheetPart worksheetPart = getWorksheetByName(spreadSheetDocument, DEFAULT_SHEET_NAME); SheetData sheetData = worksheetPart.Worksheet.GetFirstChild<SheetData>(); Cell theCell1 = worksheetPart.Worksheet.Descendants<Cell>().FirstOrDefault(c => c.CellReference == "A5"); Cell theCell2 = worksheetPart.Worksheet.Descendants<Cell>().FirstOrDefault(c => c

how to modify content in filestream while using open xml?

非 Y 不嫁゛ 提交于 2019-12-11 17:39:33
问题 In the code below, I am merging some files together and saving them in the test.docx file. However, before I merg each file, I would like to first replace the text of some content controls which are used as place holders. Can someone show me how to do that? suppose I have one content control in template2 and it is called placeholder1. How can I add text to this placeholder while usig the filestream? string fileName = Path.Combine(@"Docs\templates", "test.docx"); for (int i = 1; i < 3; i++) {

How to set table caption with OpenXML?

本小妞迷上赌 提交于 2019-12-11 17:39:01
问题 I want to set caption to my table: var caption = new TableCaption(); caption.Val = "Test"; table.Append(caption); But nothing happens. Whats wrong here? UPADATE foreach (var tabl in mainPart.Document.Body.Descendants<Table>()) { foreach (var trow in tabl.Elements<TableRow>()) { foreach (var tcell in trow.Elements<TableCell>()) { foreach (var para in tcell.Elements<Paragraph>()) { foreach (var run in para.Elements<Run>()) { foreach (var text in run.Elements<Text>()) { if ( text.Text == "my

How do I create a check box in C# using Open XML SDK

拥有回忆 提交于 2019-12-11 16:33:16
问题 I would like to create a certain number of checkbox using Open XML SDK in C#. How would I do that? Example: (Checkbox) - Shoes (Checkbox) - Shirt The checkbox count also varies. I am reading a template document, then make edits to return. I have something like this so far: string documentText; using (StreamReader reader ...) { documentText = reader.ReadToEnd(); } string addClothes = ""; Run newCheckBox = GenerateRun(); foreach(var item in ClothesList) { addClothes = item.clothing; //MY

Word OpenXml Word Found Unreadable Content

…衆ロ難τιáo~ 提交于 2019-12-11 14:51:58
问题 We are trying to manipulate a word document to remove a paragraph based on certain conditions. But the word file produced always ends up being corrupted when we try to open it with the error: Word found unreadable content The below code corrupts the file but if we remove the line: Document document = mdp.Document; The the file is saved and opens without issue. Is there an obvious issue that I am missing? var readAllBytes = File.ReadAllBytes(@"C:\Original.docx"); using (var stream = new

Copy Header and Footer to all other Documents OpenXML

半世苍凉 提交于 2019-12-11 13:29:12
问题 We have a master docx with the header and footer in and nothing else (formatted with images). We have 100s of word documents with body content but no header and footer and we want to be able to process these when we populate them and add the header and footer from the master header and footer docx. I have looked at the MSDN documentation here: https://msdn.microsoft.com/en-us/library/cc546917.aspx but it doesn't seem to work and when I open the target document the formatting is wrong and the

How to set font size in empty cell of a Word table using the Open XML SDK?

心已入冬 提交于 2019-12-11 11:59:12
问题 I am creating a table in OpenXml with C# in a Word file. I used some code mentioned in this question to set the fontsize of the text in the cells. It works fine for the cells that contain text, but the empty cells seem to be given the normal style, and with that a bigger font size, which makes the row height bigger. Here is my sample code with a single row with a single cell, where the font size should be 9: TableRow tr = new TableRow(); TableCell tc = new TableCell(); Paragraph par = new

Finding implicit page break in word document using xml parsing

ⅰ亾dé卋堺 提交于 2019-12-11 10:22:17
问题 I need to extract the first page content of a word document. If I look at the openxml for a wordML document I could see things like: <w:lastRenderedPageBreak /> or it would seem <w:br w:type="page" /> <w:br w:type="page" /> occurs when user enters an hard page break. I don't understand in what all cases <w:lastRenderedPageBreak /> occurs. It occurs in some of the implict page break cases but not all. For example: I typed some text and then pressed enter several times and cursor goes to the

Problems retrieving content controls with Open XML sdk

被刻印的时光 ゝ 提交于 2019-12-11 08:08:20
问题 I am developing a solution that will generate word-documents. The word-documents are generated on the basis of a template document which has defined content controls. Everything was working good for me when I had only one content control in my template, but after expanding the template document with more content controls, I am getting exceptions. It seems like I am not finding the content controls. This is my method: private void CreateReport(File file) { var byteArray = file.OpenBinary();