overwrite cells

Apr 17, 2011 at 1:06 PM

With hRow.CreateCell(1).SetCellValue(Int32.Parse(textBox3.Text)); 

I am able to add data to a cell, but if the cell allready contains something it errors.

 

How can I force a setvallue ? So that it overwrites the data in the cell anyway ?


Apr 17, 2011 at 6:48 PM

Nevermind I solved  it using    hRow.GetCell(1).SetCellValue(Int32.Parse(textBox3.Text)); 


Apr 17, 2011 at 7:20 PM

I'm sorry, but when I add a value to a cell the value is there in eg B24, but in G24 there is a formula doing =B24+AG24 , but this isn't performed when using the code.

If I would open the excel manually and add the value it works fine. When  I use NPOI the value is added but the formula isn't executed ???

 

Apr 17, 2011 at 7:55 PM

aaaah found it :) 

sheet1.ForceFormulaRecalculation =

true

;

Apr 18, 2011 at 1:56 PM

BUT,

the preview in windows still shows the previous cell-data and also if I collect the data from excel and show it in a datagridview, the cell-data is not updated.

I have to open the excel manually, save it , and then it is ok ????

 

Anyone an idea ??

Coordinator
Apr 22, 2011 at 10:36 PM

Are you talking about evaluating value at runtime? If so, please take a look at HSSFFormulaEvaluator class. You can learn how to use it by viewing the code in the example project called UseBasicFormulaInXls in NPOI.Examples

Apr 25, 2011 at 7:03 PM

What I mean is when I do sheet1.ForceFormulaRecalculation = true; the recalculation is only seen when the sheet is actually opened.

If I have not opened and saved it the recalculation is not seen in a datagridview nor in windows 7 explorers preview mode.

I really need to open the excelsheet and save it. If I then rerun the c-program and look in the datagridview all is well.

?

 

Coordinator
May 2, 2011 at 4:56 PM

This is by design. Because ForceFormulaRecalculation is a tag in xls, nothing else. It informs Excel to recalculate everything the xls is opened in Excel UI. However, NPOI doesn't handle this tag at runtime. NPOI doesn't equal Excel !