+ -
当前位置:首页 → 问答吧 → 导出excel问题,

导出excel问题,

时间:2011-12-13

来源:互联网

C# code

using System;
using System.Collections.Generic;

using System.Data;
using System.Data.SqlClient;
using System.Text;
using Microsoft.Office.Interop.Excel;


public static void Main(string[] args)
        {
            Microsoft.Office.Interop.Excel.Application xlApp = null;
            Microsoft.Office.Interop.Excel.Workbooks wBooks = null;
            Microsoft.Office.Interop.Excel.Workbook wBook = null;
            Microsoft.Office.Interop.Excel.Worksheet wSheet = null;
           
            Microsoft.Office.Interop.Excel.Range rg= CreateExcelForm( Convert.ToDateTime("2011-10-31 00:00:00"), "adb", "k1", "3wc", ref xlApp, ref wBooks, ref wBook, ref wSheet);
            if (rg != null)
            {
                ReleaseSource("E:/ASP.xls", xlApp, wBooks, wBook, wSheet);
            }
           


        }
private static Microsoft.Office.Interop.Excel.Range CreateExcelForm(DateTime DateTimes, string Area, string Line, string Station,
             ref Application xlApp, ref Workbooks wBooks, ref Workbook wBook, ref Worksheet wSheet)
        {
            xlApp = new Microsoft.Office.Interop.Excel.Application();
            wBooks = xlApp.Workbooks;
            wBook = wBooks.Add(System.Reflection.Missing.Value);
            wSheet = (Microsoft.Office.Interop.Excel.Worksheet)wBook.ActiveSheet;
            Microsoft.Office.Interop.Excel.Range rg = null;

  //a1-j4
                            rg = wSheet.get_Range(iColumns[0] + (Rowindex), iColumns[18] + (rowscount));
                            rg.Borders.LineStyle = 1;
                            rg.Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                            rg.Cells.VerticalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                            rg.EntireColumn.AutoFit();


                           //此处导出的内容省略
                          return rg;
          }
  现在需求如下:
             指定导出到某个文件,不替换文件的内容,在导出时,需指定导出到某个工作表!...  
             例如:在winform窗体中选中excel文件,指定导出到名称为sheet1的工作表,而sheet2和sheet3的工作表名称不被替换! 

            请问大虾,如何更改啊!

作者: hncela   发布时间: 2011-12-13

而sheet2和sheet3的工作表内容不被替换! 

作者: hncela   发布时间: 2011-12-13

不能按sheets[1]索引指定!

作者: hncela   发布时间: 2011-12-13