Jun 5

c#中导出为Excel 晴

admin365 , 02:51 , Excel , 评论(0) , 引用(0) , 阅读(54) , Via 本站原创 | |



[转载]

public void DowonExcel(string path, string[] title, List<List<string>> list)
{

object value = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Application Excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbooks workbooks = (Microsoft.Office.Interop.Excel.Workbooks)Excel.Workbooks;
Microsoft.Office.Interop.Excel.Workbook workbook = (Microsoft.Office.Interop.Excel.Workbook)workbooks.Add(value);
Microsoft.Office.Interop.Excel.Sheets sheets = (Microsoft.Office.Interop.Excel.Sheets)workbook.Worksheets;
Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];

for (int i = 0; i <title.Length; i )
{
worksheet.Cells[1, i 1] = title[i];
}
int row = 2;
foreach (List<string> details in list)
{
for (int k = 1; k <details.Count 1; k )
{
worksheet.Cells[row, k] = details[k - 1];
}
row ;
}
worksheet.Columns.AutoFit();
System.Windows.Forms.Application.DoEvents();
workbook.Saved = true;
workbook.SaveCopyAs(path);
}


[转载]原文链接: http://renhuaniang.bokee.com/viewdiary.28699904.html

百度搜索:Excel
Google搜索:Excel
雅虎搜索:Excel
SOSO搜索:Excel



Tags:
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]