• excel 数据读写 Aspose.Cells.dll


      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);
            }
  • 相关阅读:
    编写程序,验证string是ipV4地址
    TCP三次握手和四次挥手
    链表和数组的区别
    cookie和session的区别
    GET和POST的区别
    TCP和UDP的区别
    java HashMap和Hashtable的区别
    java 堆和栈的区别
    最小栈的实现
    关于几个位运算的算法分析
  • 原文地址:https://www.cnblogs.com/qc-id-01/p/8669971.html
Copyright © 2020-2023  润新知