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

解决方案 »

  1.   

    Excel.Application ThisApplication = null;
                Excel.Workbook ThisWorkbook = null;
                Excel.Worksheet ThisSheet = null;ThisApplication = new Excel.Application();
                    ThisApplication.ScreenUpdating = false;
                    ThisApplication.Visible = true;ThisWorkbook = ThisApplication.Workbooks.Add(System.Type.Missing);                ThisSheet = (Excel.Worksheet)ThisWorkbook.Sheets[1];for (int y = 0; y < nds.Count; y++)
                    {
                        XmlNode xnd = nds.Item(y);
                        ((Excel.Range)ThisSheet.Cells[y + 4, 2]).FormulaR1C1 = xnd.Attributes["AA"].Value;
                        ((Excel.Range)ThisSheet.Cells[y + 4, 3]).FormulaR1C1 = xnd.Attributes["BB"].Value;
                    }
      

  2.   

    using Excel = Microsoft.Office.Interop.Excel;
    using Office = Microsoft.Office.Core;
      

  3.   

    finally
                {
                    if (null != ThisWorkbook)
                    {
                        ThisWorkbook.Saved = true;
                    }
                    if (null != ThisApplication)
                    {
                        ThisApplication.ScreenUpdating = true;
                        ThisApplication.DisplayAlerts = false;
                        ThisApplication = null;
                    }
                }
      

  4.   

    bitpolar(独自看天) 谢谢你,可是LEADER说要用程序来操控EXCEL的格式或者自己建立一个EXCEL模板将数据填充进去,总之就是导入的格式问题.再帮我看看吧,谢谢!
      

  5.   

    自己建立一个模板就复制一下模板然后打开填充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];
      

  6.   

    //设置字号 格式 自动换行
                    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里可以录制宏获得
      

  7.   

    具体的操作可以看这里http://www.microsoft.com/china/msdn/library/office/office/UndstaExcelObjModNETDev.mspx
    从 .NET 开发人员的角度理解 Excel 对象模型