private void Form1_Load(object sender, EventArgs e) { writeExcel(); Workbook workbook = new Workbook(); workbook.Open("123.xls"); Cells cells = workbook.Worksheets[0].Cells; for (int i = 0; i < cells.MaxDataRow + 1; i++) { string ss = ""; for (int j = 0; j < cells.MaxDataColumn + 1; j++) { string s = cells[i, j].StringValue.Trim(); //一行行的读取数据,插入数据库的代码也可以在这里写 ss += s + ","; } File.AppendAllText("新数据.txt", ss.Substring(0, ss.Length - 1)+" "); } } /// <summary> /// 写入excel /// </summary> public void writeExcel() { string fileName ="12.xls"; Workbook book = new Workbook(); Worksheet sheet = book.Worksheets[0]; Cells cells = sheet.Cells; int Colnum = 123;//表格列数 int Rownum = 123;//表格行数 //生成行 列名行 for (int i = 0; i < Colnum; i++) { cells[0, i].PutValue("列名"); } //生成数据行 for (int i = 0; i < Rownum; i++) { for (int k = 0; k < Colnum; k++) { cells[1 + i, k].PutValue("数据"); } } book.Save(fileName); }