中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

ASP.NET用MyXls實現(xiàn)Excel數(shù)據(jù)導(dǎo)出

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
MyXls是用C#開源項目,可以應(yīng)用于asp.net 或者 .net應(yīng)用程序上。它根據(jù)微軟公開的Excle文檔格式文件(BIFF),以二進制格式直接生成excel文檔,支持Excel versions 97 - 2007 。這意味著你可以不用在服務(wù)器上安裝office就能夠以excle格式輸出數(shù)據(jù)庫中存儲的數(shù)據(jù)了,這對于許多項目來說都是很有用的。

關(guān)于MyXls它的主頁上是這樣描述的:

Writes and now Reads Excel files quickly and easily, including formatting. Generate Excel files for ASP.NET sites or .NET applications. Doesn't require Excel on the server or any licensing $. Compatible with Excel versions >= 97.

其功能之強大也不是誰能一時就能掌握的,我在這里主要介紹一下如何用它實現(xiàn)數(shù)據(jù)導(dǎo)出,關(guān)于用它讀取和生成Excel我還沒有用過也就不做過多發(fā)言了,各位需要可以再google一下!

第一步,當(dāng)然是下在MyXls,地址:http://sourceforge.net/projects/myxls/

第二步,添加引用org.in2bits.MyXls.dll

第三步,實現(xiàn)數(shù)據(jù)導(dǎo)出,我這里是將一個DataTable作為數(shù)據(jù)導(dǎo)出,導(dǎo)出后內(nèi)容格式和DataTable一致,具體代碼如下:

    private void Output(DataTable dt)  
    {  
        org.in2bits.MyXls.XlsDocument doc = new org.in2bits.MyXls.XlsDocument();  
        doc.FileName = DateTime.Now.ToString().Replace("-", "").Replace(":", "").Replace(" ", "") + ".xls";//excel文件名稱  
        org.in2bits.MyXls.Worksheet sheet = doc.Workbook.Worksheets.AddNamed("sheet1");//Excel工作表名稱  
        org.in2bits.MyXls.Cells cells = sheet.Cells;  
        int colnum = dt.Columns.Count;//獲取DataTable列數(shù)  
      
        for (int i = 0; i < colnum; i++)  
        {  
            cells.Add(1, (i + 1), dt.Columns[i].Caption.ToString());//導(dǎo)出DataTable列名  
        }  
        for (int i = 0; i < dt.Rows.Count; i++)  
        {  
            for (int j = 0; j < colnum; j++)  
            {  
                cells.Add((i + 2), (j + 1), dt.Rows[i][j].ToString());  
            }  
        }  
        //doc.Save(@"D:\");  //保存到指定位置  
        doc.Send();//把寫好的excel文件輸出到客戶端  
    }  

標(biāo)簽: Google 代碼 服務(wù)器 數(shù)據(jù)庫

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:java 用jdbc連接mysql 并執(zhí)行sql語句

下一篇:NSUserdefaults用法總結(jié)