1. Read
Using (FileStream stream = new FileStream (@ "c: \ Customer Info. xls", FileMode. Open, FileAccess. Read ))
{
HSSFWorkbook workbook = new HSSFWorkbook (stream );
MessageBox. Show (workbook. GetSheetName (0 ));
}
• Read string data MessageBox. Show (sheet. GetRow (3). GetCell (4). StringCellValue); read numeric data NumericCellValue. • Determine the cell data type: Read GetCell (4). CellType and compare it with the constants defined in the HSSFCell class. • Use region: end row: Last RowNum2. write to Excel
HSSFWorkbook workbook = new HSSFWorkbook ();
HSSFSheet sheet = workbook. CreateSheet ();
HSSFRow row = sheet. CreateRow (0 );
Row. CreateCell (0, HSSFCell. CELL_TYPE_STRING). SetCellValue ("Hello ");
Row. CreateCell (1, HSSFCell. CELL_TYPE_NUMERIC). SetCellValue (3.14 );
Using (FileStream stream = new FileStream (@ "c: \ 1.xls", FileMode. OpenOrCreate, FileAccess. ReadWrite ))
{
Workbook. Write (stream );
}
• NPOI, MyXls, etc. NPOI can analyze the Excel file formats and perform common Excel operations without relying on Excel, saving resources and having no security or performance issues. It is the most suitable for ASP.net. Only xls files can be processed, and new versions of Excel files such as xlsx cannot be processed. OpenXML is also used to process xlsx.