Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excel 2007 Shared formula Error after setting cell formula to null #829

Closed
AdPig opened this issue May 9, 2022 · 2 comments
Closed

Excel 2007 Shared formula Error after setting cell formula to null #829

AdPig opened this issue May 9, 2022 · 2 comments
Labels
Milestone

Comments

@AdPig
Copy link

AdPig commented May 9, 2022

I have a Excel 2007 file(xlsx) , C2 formula value=A2 * B2/100 ,if I select C2,drag From C2 to C4,then C3 to C4 Cell Value as follows:
C3=A3 * B3/100
C4=A4 * B4/100
at last i want clear C3 formula , I run follows code,but have error;

In a strange way, I Manual input C3 to C4 formula ,run follows code,but No error;

The Code is very sample,as follows:

       string excelFilePath = @"d:\test2.xlsx";
        IWorkbook workbook = null;
        using (FileStream fs = new FileStream(excelFilePath, FileMode.Open, FileAccess.Read))
        {
            workbook = new XSSFWorkbook(fs);
            ISheet sheet = workbook.GetSheetAt(0);
            ICell cell = sheet.GetRow(2).GetCell(2);
            cell.CellFormula = null;
        }
        FileStream sw = File.Create(excelFilePath);
        workbook.Write(sw);
        sw.Close();

errors,as follows:
image

test file:
TEST2.xlsx

ref infors:
NPOI Version : V2.5.6
.Net framework Version : 4.5

@tonyqus
Copy link
Member

tonyqus commented Jun 5, 2022

There is a removeFormula method in POI. I'll test if this works after migration

@tonyqus tonyqus added bug and removed enhancement labels Jun 5, 2022
@tonyqus tonyqus changed the title Excel 2007 Shared formula Error Excel 2007 Shared formula Error after setting cell formula to null Jun 5, 2022
@tonyqus
Copy link
Member

tonyqus commented Jun 5, 2022

I found that the set-null code in SetCellFormula doesn't call XSSFSheet.OnDeleteFormula. It only calls XSSFWorkbook.OnDeleteFormula, which is not enough.

((XSSFWorkbook)wb).OnDeleteFormula(this);

@tonyqus tonyqus closed this as completed in b5b21c5 Jun 5, 2022
artem-iron pushed a commit to jake-codes-at-5-am/npoi that referenced this issue Jun 29, 2022
Add RemoveFormula method and fix nissl-lab#829
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants