C # Use NPOI to export an Excel class (simple Edition ),
Code:
Using System. data; using System. IO; using NPOI. HSSF. userModel; using NPOI. SS. userModel; namespace ahwildlife. utils {// <summary> // Excel tool class // use NPOI to generate Excel /// </summary> public class ExcelUtil {# region to generate Excel /// <summary> /// generate an Excel file // </summary> public static void CreateExcel (DataTable dt, string path) {HSSFWorkbook workbook = new HSSFWorkbook (); ISheet sheet = string. isNullOrEmpty (dt. tabl EName )? Workbook. createSheet ("Sheet1"): workbook. createSheet (dt. tableName); // create a worksheet # region title IRow row = sheet. createRow (0); // Add a row in the worksheet for (int I = 0; I <dt. columns. count; I ++) {ICell cell = row. createCell (I); // Add a cell column to the row. setCellValue (dt. columns [I]. columnName); // set the column content} # endregion # region fill data for (int I = 1; I <= dt. rows. count; I ++) // traverse the {able row {DataRow dataRow = dt. rows [I-1]; row = sheet. createRow (I); // Add a row for (int j = 0; j <dt. columns. count; j ++) // traverse the DataTable column {ICell cell = row. createCell (j); // Add a cell column to the row. setCellValue (dataRow [j]. toString (); // set column content} # endregion # region output to Excel MemoryStream MS = new MemoryStream (); workbook. write (MS); using (FileStream fs = new FileStream (path, FileMode. create, FileAccess. write) {byte [] bArr = ms. toArray (); fs. write (bArr, 0, bArr. length); fs. flush () ;}# endregion }# endregion }}View Code
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:
# Include <stdio. h>
Struct STU // define a struct
{
Int num;
} Stu;
Int main ()
{
Struct STU * p; // defines a struct pointer.
P = stu; // p points to the struct variable stu.
Stu. num = 100; // attaches an initial value to the struct member num.
Printf ("% d", p-> num); // output the num value in stu
Return;
}
As you can see, the-> method is to reference the variable in the struct !!
Format: p-> struct member (such as p-> num)
The function is equivalent to stu. num or (* p). num.
I don't know. You don't understand, and don't understand call me. O (∩ _ ∩) O ~
Hope to adopt it.