Home > Net >  Written in NPOI to an existing EXCEL file data, how to operate to the original data are not covered,
Written in NPOI to an existing EXCEL file data, how to operate to the original data are not covered,

Time:09-19

I write data in NPOI to existing EXCEL, EXCEL A1 cell data originally, want to on the basis of writing new data in the A2 cell, use the following code found A1 cell disappeared, excuse me how to operate to get A1 A2 data at the same time?
 
HSSFWorkbook workbook=new HSSFWorkbook ();//XLS format
ISheet sheet=workbook. CreateSheet ();
IRow row=sheet. CreateRow (0);//from the first line wrote
Row. CreateCell (1, CellType. Numeric). SetCellValue (3.14);
Using (FileStream stream=new FileStream (@ "C: \ test1. XLS", FileMode. OpenOrCreate, FileAccess. ReadWrite))
{
Workbook. Write (stream);
The Dispose ();
}

CodePudding user response:

IRow row=sheet. CreateRow (0)
Into a sheet. GetRow (0) line
Of course, first to determine whether the number of lines & gt;=1

CodePudding user response:

Sheet. CreateRow is new, and you want to modify

CodePudding user response:

refer to the second floor xuzuning response:
sheet. The CreateRow is new, and you need to modify
yes, that is how to modify, mostly is the new online

CodePudding user response:

reference 1st floor stherix response:
IRow row=sheet. The CreateRow (0)
Into a sheet. GetRow (0) line
Of course, first to determine whether the number of lines & gt;=1
prompt "will object reference not set to an instance of an object"

CodePudding user response:

Find the information, https://blog.csdn.net/fujie724/article/details/21017873, thank you!

CodePudding user response:

Excuse me, how do you solve for the original data is not overwritten
  •  Tags:  
  • C#
  • Related