openxml-sdk

How can I get the specific column in excel worksheet using DocumentFormat.OpenXml C#?

这一生的挚爱 提交于 2021-02-20 02:14:55
问题 As the title, I would like to get a specific column in excel worksheet using OpenXML in C# for setting hidden property. Like that: var columns = worksheet.GetFirstChild<Columns>(); var column = columns.FirstOrDefault(c=>c.ColumnIndex == 4); column.Hidden = true; The code above is just a sample for my idea. Is there any way for solving my problem? 回答1: per: https://docs.microsoft.com/en-us/office/open-xml/how-to-get-a-column-heading-in-a-spreadsheet , workSheetPart.Worksheet.Descendants() in

How can I get the specific column in excel worksheet using DocumentFormat.OpenXml C#?

泄露秘密 提交于 2021-02-20 02:11:51
问题 As the title, I would like to get a specific column in excel worksheet using OpenXML in C# for setting hidden property. Like that: var columns = worksheet.GetFirstChild<Columns>(); var column = columns.FirstOrDefault(c=>c.ColumnIndex == 4); column.Hidden = true; The code above is just a sample for my idea. Is there any way for solving my problem? 回答1: per: https://docs.microsoft.com/en-us/office/open-xml/how-to-get-a-column-heading-in-a-spreadsheet , workSheetPart.Worksheet.Descendants() in

Inserting image corrupts Open XML SDK generated Word file

主宰稳场 提交于 2021-02-11 06:24:50
问题 I have tried to adapt the code in https://docs.microsoft.com/en-us/office/open-xml/how-to-insert-a-picture-into-a-word-processing-document to insert an image to a table cell in my .Net Core MVC app. However, inserting the image just corrupts the word file. I have noticed that when I extract the corrupt docx file, the "media" folder is outside the "word" folder. However, when I manually add an image to a docx file, the "media" folder is present inside the "word" folder. ...code here...

Not able to access the Word Document on my system using the UWP application

走远了吗. 提交于 2021-02-10 07:54:10
问题 I am trying to edit a existing Word document using the UWP app (Universal Windows). But for some reason I am getting "File does not exist" error. I have tried using the below code to access the word document: using(WordprocessingDocument wordDoc = WordprocessingDocument.Open("C:\\Users\\Public\\Desktop\\Doc1.docx", true)) { } System.IO.FileNotFoundException: 'Could not find document' 回答1: Based on further clarification in the comments section, please see the following instructions. Add your

Not able to access the Word Document on my system using the UWP application

一笑奈何 提交于 2021-02-10 07:53:03
问题 I am trying to edit a existing Word document using the UWP app (Universal Windows). But for some reason I am getting "File does not exist" error. I have tried using the below code to access the word document: using(WordprocessingDocument wordDoc = WordprocessingDocument.Open("C:\\Users\\Public\\Desktop\\Doc1.docx", true)) { } System.IO.FileNotFoundException: 'Could not find document' 回答1: Based on further clarification in the comments section, please see the following instructions. Add your

How to read xslx with open XML SDK based on columns in each row in C#?

若如初见. 提交于 2021-02-10 05:31:09
问题 I am trying to read some .xslx files with the open xml sdk, but I'm really struggeling finding any good examples. What I want to do is to read the entire XSLX file and loop through all of the rows and extract the cellvalue/celltext from the columns i specify. Like the following: GetCellText(rowId, ColumnLetter) Is this possible? 回答1: Helpers: private static string GetColumnName(string cellReference) { if (ColumnNameRegex.IsMatch(cellReference)) return ColumnNameRegex.Match(cellReference)

How to read xslx with open XML SDK based on columns in each row in C#?

折月煮酒 提交于 2021-02-10 05:30:40
问题 I am trying to read some .xslx files with the open xml sdk, but I'm really struggeling finding any good examples. What I want to do is to read the entire XSLX file and loop through all of the rows and extract the cellvalue/celltext from the columns i specify. Like the following: GetCellText(rowId, ColumnLetter) Is this possible? 回答1: Helpers: private static string GetColumnName(string cellReference) { if (ColumnNameRegex.IsMatch(cellReference)) return ColumnNameRegex.Match(cellReference)

Creating a QueryTable in an Open XML Spreadsheet using C#

对着背影说爱祢 提交于 2021-02-07 18:36:16
问题 I have a number of report-generating ASMX webservices and would like to help our users by adding a link to download a .XLSX file containing a pre-configured and formatted Query Table for the webservice. They will then be able to build their own graphs and derived reports as they currently do, but also be able to refresh the data without rebuilding everything. var machStore = IsolatedStorageFile.GetMachineStoreForAssembly(); string fileName = Path.ChangeExtension(Path.GetRandomFileName(), "

Filling a cell with a solid color, using OpenXML that preserves otherwise existing sheet format

*爱你&永不变心* 提交于 2021-01-29 11:00:00
问题 The following takes the format of existing sheet sSheet and creates a red font (along with some timestamp content) at A19: using (SpreadsheetDocument document = SpreadsheetDocument.Open(sPath, true)) { IEnumerable<Sheet> sheets = document.WorkbookPart.Workbook.Descendants<Sheet>().Where(s => s.Name == sSheet); WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.FirstOrDefault().Id); Worksheet worksheet = worksheetPart.Worksheet; WorkbookStylesPart styles =

OpenXML: Auto Size column width in Excel

老子叫甜甜 提交于 2021-01-20 15:42:27
问题 I have written a code to generate Excel file using OpenXML. Below is the code which generates the Columns in the Excel. Worksheet worksheet = new Worksheet(); Columns columns = new Columns(); int numCols = dt1.Columns.Count; for (int col = 0; col < numCols; col++) { Column c = CreateColumnData((UInt32)col + 1, (UInt32)numCols + 1, 20.42578125D); columns.Append(c); } worksheet.Append(columns); Also, I tried below line to create columns. Column c = new Column { Min = (UInt32Value)1U, Max =