資源簡介
自己用c#編寫的財務管理系統中生成資產負債表(excel)的類,形成表的樣式已排好,只需根據需要添加數據庫的數據即可。
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
namespace?ClassLibrary1
{
????public?class?Class1
????{
???????public?void?Export(string?btitle)
????????{
????????????string?rq?=?DateTime.Now.Year.ToString()?+?“年“?+?DateTime.Now.Month.ToString()?+?“月“?+?DateTime.Now.Day.ToString()?+?“日“;
????????????//建立Excel對象
????????????Excel.Application?excel?=?new?Excel.Application();
????????????excel.Application.Workbooks.Add(true);
????????????excel.Visible?=?true;
????????????Excel.Range?range?=?excel.get_Range(excel.Cells[1?1]?excel.Cells[1?8]);//選中范圍第一行的1到7列的單元格
????????????range.MergeCells?=?true;//合并上述范圍的單元格
????????????//excel.get_Range(excel.Cells[1?1]?excel.Cells[1?dgv.ColumnCount]).Cells.Font.Name?=?“宋體“;
????????????excel.ActiveCell.Font.Name?=?“宋體“;
????????????excel.ActiveCell.Font.Bold?=?true;
????????????excel.ActiveCell.FormulaR1C1?=?btitle;//合并的單元格為當前活動單元格,設置其內容為表頭
????????????excel.ActiveCell.HorizontalAlignment?=?Excel.XlHAlign.xlHAlignCenter;//設置其內容在合并的大單原格中居中
????????????excel.ActiveCell.Font.Size?=?“15“;
????????????//excel.get_Range(excel.Cells[1?1]?excel.Cells[1?3]).Cells.Font.Size?=?“15“;
????????????//excel.Cells.EntireColumn.AutoFit();
????????????excel.Caption?=?“記賬憑證導出數據“;
????????????for?(int?i?=?3;?i?39;?i++)
????????????{
????????????????for?(int?j?=?1;?j?9;?j++)
????????????????{
????????????????????excel.get_Range(excel.Cells[i?-?1?j]?excel.Cells[i?-?1?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].ColorIndex?=?28;//設置選定單元格的下邊框顏色
????????????????????excel.get_Range(excel.Cells[i?-?1?j]?excel.Cells[i?-?1?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].Linestyle?=?Excel.XlLinestyle.xlContinuous;//
????????????????????excel.get_Range(excel.Cells[i?-?1?j]?excel.Cells[i?-?1?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeBottom].Weight?=?Excel.XlBorderWeight.xlThin;//
????????????????????excel.get_Range(excel.Cells[i?j]?excel.Cells[i?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeLeft].ColorIndex?=?38;//設置選定單元格的下邊框顏色
????????????????????excel.get_Range(excel.Cells[i?j]?excel.Cells[i?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeLeft].Linestyle?=?Excel.XlLinestyle.xlContinuous;//
????????????????????excel.get_Range(excel.Cells[i?j]?excel.Cells[i?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeLeft].Weight?=?Excel.XlBorderWeight.xlThin;//
????????????????????excel.get_Range(excel.Cells[i?j]?excel.Cells[i?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeRight].ColorIndex?=?38;//設置選定單元格的下邊框顏色
????????????????????excel.get_Range(excel.Cells[i?j]?excel.Cells[i?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeRight].Linestyle?=?Excel.XlLinestyle.xlContinuous;//
????????????????????excel.get_Range(excel.Cells[i?j]?excel.Cells[i?j]).Cells.Borders[Excel.XlBordersIndex.xlEdgeRight].Weight?=?Excel.XlBorderWeight.xlThin;//
????????????????}
????????????}
????????????//excel.get_Range(excel.Cells[3?1]?excel.Cells[40?3]).Cells.B
評論
共有 條評論