C# Excel formula indicator - c#

I want to convert the data of Excel file in the DataTable for edit. But cells with formulas should not be editable. How do I find that the cell contains a formula, if I get the calculated value in it? Thanks.

Try the .HasFormula property of Range
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.range.hasformula.aspx

Range.SpecialCellsmethod enables to get cells with constant values or formulas.

Related

C# - Find all matches in worksheet using Excel

enter image description here
I would like to find all "NC2" mathces in this worksheet (later the B column values).
I tried with range.find but I got back only one result.
How can I read out these cells? (Which contains NC2)
what I would do is do a data -> filter to get all the cells.
if it helps, conditional formatting would also help to visually find all the cells containing NC2.

Data missing when excel export from gridview

During exporting excel from gridview the data of a column known as Account Number prefixes 0 are removed. Please guide me for the same
You need to get Account number into a string variable so as to protect leading zero, then while exporting to excel, you need to set cell type to string before you set the value to cell.

Reading formula calculated value from excel cell in c#

I am using linqtoexcel for reading from a excel sheet. the problem i face is that i can't read the formula calculated value from a cell, instead i get the actual value of the cell. Is there any way to read the end value of the cell from the excel sheet using linqtoexcel or by some other means.
linqtoexcel uses OleDB to access the sheet's data, and since OleDB does not allow the formulas to be accessed, you can't read the formula from the excel cell. You can only view the value for the cell.

Can you populate a range in ClosedXML (C#)

I wanted to see if you can populate a range all at once from an array when using closedXML instead of populating a single cell at a time. Also, if it is possible to set a range from an array, would that be faster than looping through cell by cell and populating each cell?
You can try to insert data as a DataTable and see if it will speed up document creation. But as I can see in source code, there is no optimisation possible whatsoever against single cell population (but I can be wrong).
You can do:
cell.Value = yourArray;
See the section "Inserting Data/Tables" of the Documentation.

Excel calculation problems

I have .xlsx document in which I need to import some values to cells with defined names. Few of those cells are formatted as currency and values that I am importing in those cells are of decimal type which I import in this manner:
cell.CellValue = new CellValue(value.ToString().Replace(",", "."));
In the same spreadsheet there are a few cells that have a formula in which currency cells I imported are used (eg., I am importing value in cell H27 with defined name Total, and in the field I27 there is a formula =Total*0.23).
After import is complete, values are successfully imported (and correctly formatted as currency), but formula cells are not correctly calculated until I either click on formula check marks for each formula cell or I change the currency value (in this case, all formulas containing this cell are refreshed).
What do I have to do for cells with formulas to automatically calculate values after import is completed?
I've figured it out. The cells with formula have <CellFormula> fields inside of them. Those fields have bool attribute CalculateCell which, if set to true, tells Excel to calculate the formula after opening the file. Since I don't know up front which formula cells are affected by the cells, I manage all of them like this:
foreach (var cell in sheetData.Descendants<CellFormula>())
cell.CalculateCell = true;

Categories