ASP.NET中利用OWC組件產生EXCEL表

來源:互聯網
上載者:User

//請在項目中引用OWC11(COM組件)

OWC11.SpreadsheetClass xlsheet =new OWC11.SpreadsheetClass();
   //合併儲存格
   xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,14]).set_MergeCells(true);
   xlsheet.ActiveSheet.Cells[1,1] ="一級帳表";
   //字型加粗
   xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,14]).Font.set_Bold(true);
   //儲存格文本水平置中對齊
   xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,14]).set_HorizontalAlignment(OWC11.XlHAlign.xlHAlignCenter );
   //設定字型大小
   xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[1,14]).Font.set_Size(14);
   //設定列寬
   xlsheet.get_Range(xlsheet.Cells[1,3],xlsheet.Cells[1,3]).set_ColumnWidth(50);
   

   //畫邊框線
   xlsheet.get_Range(xlsheet.Cells[1,1],xlsheet.Cells[10,15]).Borders.set_LineStyle(OWC11.XlLineStyle.xlContinuous  );
   

   //寫入資料  (這裡可根據需要由DS產生)
   for (int row=2;row<10;row++)   //注意寫入資料時,必須從第一行開始寫EXCEL裡沒有第"0"行
   {
    for(int i = 0 ;i< 15 ;i++)
    {
     xlsheet.ActiveSheet.Cells[row, i + 1] =123.456;
    }
   }
   try
   {
    //將數字格式化為金額(要格式化的儲存格內的值必須為數值型)
    xlsheet.get_Range(xlsheet.Cells[2,1],xlsheet.Cells[10,15]).set_NumberFormat("¥#,##0.00");
    xlsheet.Export("D://ExportToExcel//TestOWC.xls",OWC11.SheetExportActionEnum.ssExportActionNone,OWC11.SheetExportFormat.ssExportXMLSpreadsheet);
    Response.Write("Export OK");
   }
   catch
   {
   }

至於其它功能還有待於深入瞭解,互相學習!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.