日期:2014-05-20  浏览次数:20922 次

C#程序实现导入EXCEL
sql   server   2000中的表导入EXCEL中,EXCEL的格式是固定好的,只要向其中填充数据即可,大家帮忙看看吧

------解决方案--------------------
finally
{
if (null != ThisWorkbook)
{
ThisWorkbook.Saved = true;
}
if (null != ThisApplication)
{
ThisApplication.ScreenUpdating = true;
ThisApplication.DisplayAlerts = false;
ThisApplication = null;
}
}
------解决方案--------------------
自己建立一个模板就复制一下模板然后打开填充

ThisApplication = new Excel.Application();
ThisWorkbook = ThisApplication.Workbooks.Open(FilePath, System.Type.Missing, true,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing,
System.Type.Missing, System.Type.Missing, System.Type.Missing, System.Type.Missing);

ThisSheet = (Excel.Worksheet)ThisWorkbook.Sheets[1];
------解决方案--------------------
//设置字号 格式 自动换行
ThisSheet.Cells.Font.Size = 10;
ThisSheet.Cells.NumberFormatLocal = "@ ";
ThisSheet.Cells.WrapText = true;

//设置列宽
((Excel.Range)ThisSheet.Columns[ "A:A ", System.Type.Missing]).ColumnWidth = 0.85;
((Excel.Range)ThisSheet.Columns[ "B:B ", System.Type.Missing]).ColumnWidth = 17.5;
((Excel.Range)ThisSheet.Columns[ "C:C ", System.Type.Missing]).ColumnWidth = 10.5;
((Excel.Range)ThisSheet.Columns[ "D:D ", System.Type.Missing]).ColumnWidth = 38.5;

((Excel.Range)ThisSheet.Cells[3, 2]).FormulaR1C1 = "疏影横斜水清浅 ";
((Excel.Range)ThisSheet.Cells[3, 3]).FormulaR1C1 = "暗香浮动月黄昏 ";


这些格式在Excel里可以录制宏获得
------解决方案--------------------
具体的操作可以看这里

http://www.microsoft.com/china/msdn/library/office/office/UndstaExcelObjModNETDev.mspx
从 .NET 开发人员的角度理解 Excel 对象模型