Home > Net >  When reading a excel OpenXML read data does not accord with excel
When reading a excel OpenXML read data does not accord with excel

Time:09-30

Using openxml read excel, and then read the data into the database, there is a problem: read a cell's data, such as the excel value is 0.8, the debug code, read the value is 0.32, the cell is a formula, values are calculated automatically, and below is my code: addressName is cell name (such as: Q5, R13)

 
The Cell theCell=worksheet. Descendants () Where (c=& gt; Arthur c. ellReference==addressName). FirstOrDefault ();
If (theCell!=null)
{
Value=https://bbs.csdn.net/topics/theCell.InnerText;
If (theCell CellFormula!=null)
{
If (theCell CellValue!=null)
{
Value=https://bbs.csdn.net/topics/theCell.CellValue.InnerText;
}
The else {
return null;
}
}
}


Such as read Q51 column line 51 (Q) value, theCell. The InnerText value is "=ROUND (SUM (I51 J51 * and L51 * K51, M51 N51 * and P51 * O51), 2) 0.320000", theCell. CellValue. The InnerText value is "0.320000", but actually in excel Q51 value is 0.8, the odd thing was not Q column more than some value can read wrong, only a few misread,
The excel sheet is password protected, remove the password protection will not read wrong, but can't read the formula, is give sheet to encrypt code below:
 
SheetProtection SheetProtection=new SheetProtection () {Sheet=true, Objects=true, Scenarios,=true, the Password="* * * *"};
Worksheet. InsertAfter (sheetProtection, ws. GetFirstChild ());


What a great god met this kind of situation or is there a way to solve, the trouble to help me, thank you!

CodePudding user response:

What is the difference between is round?
You to set up a file, need not formula, write Numbers in directly, then read compare have a look

CodePudding user response:

Isn't the problem the rounded rounded cannot turn 0.8 to 0.32, there is no formula is ok

CodePudding user response:

=ROUND (SUM (I51 J51 * and * K51 L51, M51 N51 * and * O51 P51), 2) 0.320000, this is the formula in the Excel?
Not in a component, like epplus is good too
  • Related