Reading formula calculated value from excel cell in c# - 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.

Related

How to get Excel formula in C # using OleDb?

I need to get the formula contained in an Excel cell. I'm using OleDb to access the spreadsheet, would you like to know if you have how to use it to access a formula in a cell?

LinqToCsv Set Column Width

I am using LinqToCsv to export data from a database to a csv file. One of the columns is a DateTime object. Upon export, the DateTime column shows up as "#######" until I manually expand the column width to fit the entire DateTime output. Is there a way to manually set column widths so that I don't have to manually expand the row every time?
A csv file has no concept of column widths. You could possibly export an .xlsx file instead using a library such as EPPlus
CSV has no format attached. It is a plain text file comma/semicolon separated. You see the file that way because Excel is showing "empty" style for it. If you open the file with a notepad you´ll see the data correctly.
If you need any style you´ll have to migrate to a XLSX or XLS file.

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.

C# Excel formula indicator

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.

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