closedxml

How to mix Excel Interop with ClosedXml: styles

有些话、适合烂在心里 提交于 2021-02-10 06:54:19
问题 I am trying to achieve the following in an Excel VSTO add-in: Copying/applying cell formatting from the original version of an Excel file. Reason: while processing Excel files, we occasionally need to change the style/coloring of a file in order to be able to process certain cells only. After the file has been processed, we need to restore the original cell formats. For that purpose, I wrote a VSTO add-in. It reads the orignal file, iterates over all used cells and applies the formatting of

How to set multiple filters in closedXML

我的梦境 提交于 2021-01-29 09:47:12
问题 There are two unanswered questions out there on this: Applying multiple filters in ClosedXML (SetAutoFilter) and ClosedXML Excel filter rows by values in multiple columns This code will leave a single filter on the last range: var wb = new XLWorkbook(); var ws = wb.Worksheets.Add("AutoFilter"); ws.Cell("A1").Value = "Names"; ws.Cell("A2").Value = "John"; ws.Cell("A3").Value = "Hank"; ws.Cell("A4").Value = "Dagny"; var r1 = ws.Range("A1", "A4"); r1.SetAutoFilter(); ws.Cell("B1").Value = "Names

Applying multiple filters in ClosedXML (SetAutoFilter)

好久不见. 提交于 2021-01-29 03:44:16
问题 I am applying filters for multiple columns via ClosedXML; however, only the last one is applied. Those filters work when they are alone. How can I apply all of them? I found similar question here ClosedXML Excel filter rows by values in multiple columns But there is no correct answer. Here is the code: var wb = new XLWorkbook(loc1); var ws2 = wb.AddWorksheet("Итоги"); var ws1 = wb.Worksheet(1); var rowCount = ws1.RowsUsed().Count(); ws1.Range(ws1.Cell(3,1), ws1.LastCellUsed()).SetAutoFilter()

Applying multiple filters in ClosedXML (SetAutoFilter)

◇◆丶佛笑我妖孽 提交于 2021-01-29 03:36:10
问题 I am applying filters for multiple columns via ClosedXML; however, only the last one is applied. Those filters work when they are alone. How can I apply all of them? I found similar question here ClosedXML Excel filter rows by values in multiple columns But there is no correct answer. Here is the code: var wb = new XLWorkbook(loc1); var ws2 = wb.AddWorksheet("Итоги"); var ws1 = wb.Worksheet(1); var rowCount = ws1.RowsUsed().Count(); ws1.Range(ws1.Cell(3,1), ws1.LastCellUsed()).SetAutoFilter()

Can closedXML write out an HTML table for Excel

心不动则不痛 提交于 2021-01-28 13:54:54
问题 I have an HTML table that is dynamic and has tags: table, th, thead, td, tbody, tr and a div at the end It also has colspans too. Can closedXML just import this into a worksheet as is and render it out as XML? 回答1: No, ClosedXML can not import HTML. You have to parse the HTML yourself (using something like HTML Agility Pack) and put the content of each cell in the HTML table in the corresponding cell of the ClosedXML spreadsheet. 来源: https://stackoverflow.com/questions/23257900/can-closedxml

Optimizing performance for ClosedXML loops and row deletion

最后都变了- 提交于 2020-05-17 06:11:51
问题 I'm reading an Excel file and looping through the rows, deleting those that meet a condition using (var wb = new XLWorkbook(path)) { var ws = wb.Worksheet(sheet); int deleted = 0; for (int row_i = 2; row_i <= ws.LastRowUsed().RowNumber(); row_i++) { ExcelRow row = new ExcelRow(ws.Row(row_i-deleted)); row.styleCol = header.styleCol; K key = keyReader(row); if (!writeData(row,dict[key])) deleted++; } wb.Save(); } The code is very slow for a file with thousands of rows, even without deletions,

C# closed XML library with .net core 3.1.1 - works when debugging but not when compiled

笑着哭i 提交于 2020-03-25 16:55:03
问题 when I run code via visual studio (IIS Express) it runs fine and exports xl spreadsheet. var wb = new XLWorkbook(); var ws = wb.Worksheets.Add(dt, "Sheet1"); wb.SaveAs(fileName); However when I compile and run on either IIS or IIS Express (on exactly same machine), I get the error Could not find a part of the path 'C:\...' Very wierd! 来源: https://stackoverflow.com/questions/60663348/c-sharp-closed-xml-library-with-net-core-3-1-1-works-when-debugging-but-not-w

C# closed XML library with .net core 3.1.1 - works when debugging but not when compiled

独自空忆成欢 提交于 2020-03-25 16:53:27
问题 when I run code via visual studio (IIS Express) it runs fine and exports xl spreadsheet. var wb = new XLWorkbook(); var ws = wb.Worksheets.Add(dt, "Sheet1"); wb.SaveAs(fileName); However when I compile and run on either IIS or IIS Express (on exactly same machine), I get the error Could not find a part of the path 'C:\...' Very wierd! 来源: https://stackoverflow.com/questions/60663348/c-sharp-closed-xml-library-with-net-core-3-1-1-works-when-debugging-but-not-w

How to get the value of excel sheet cell using their Field Name

a 夏天 提交于 2020-01-17 13:57:06
问题 I want to Extract data from Excel sheet according to header i have specifies in the Sheet. I am using ClosedXML and getting data using cell Number.Below is my Code. FileInfo fi = new FileInfo(path1); //Open uploaded workbook var workBook = new XLWorkbook(fi.FullName); //Get the first sheet of workbook var worksheet = workBook.Worksheet(1); var firstRowUsed = worksheet.FirstRowUsed(); var categoryRow = firstRowUsed.RowUsed(); /Get the column names from first row of excel Dictionary<int, string

ClosedXML Excel filter rows by values in multiple columns

六眼飞鱼酱① 提交于 2020-01-15 03:24:11
问题 I have a Excel file with several thousand rows and columns up to "BP". I need to filter all of these rows by specific values in columns C and BP. I tested the filter functionality in ClosedXML as per the code below. When I apply a filter to one column all works well and the data is saved in the new file. When I try to apply two filters, the last one executed is the one that is applied. I have tried to use the worksheet as a Range/Table, same filtering problem. I eventually created the "rows"