需要的功能是这样的。有一个excel模板,里面好多sheet页,我要把这个模板读出来,将DATASET中的数据逐行写进这个模板的第一个sheet页中,然后另存为另一个excel文件。哪位高人指点一下啊。另外的要求就是接照某一列的值不同,另存为不同的excel文件。原来我想把这个模板的列标题读出,再组合dataset导入到excel文件中,但是这个模板有很多sheet页,不能丢失。所以不知如何处理了。

解决方案 »

  1.   

    1.create a new xls file from xlt---temp.xls
    2.create entries to temp.xls
    2.rename temp.xlshttp://tech.163.com/06/0417/09/2ETC8KDJ0009159H.htmlif the datasoruce from sql,then you can using following :
    http://support.microsoft.com/default.aspx?scid=kb;zh-cn;295646
      

  2.   

    http://community.csdn.net/Expert/topic/4760/4760677.xml?temp=.7889063看下这个对你有用不但是这个模板有很多sheet页,不能丢失。所以不知如何处理了你将它当做模版来打开呀
      

  3.   

    oMissing = System.Reflection.Missing.Value
                myApp = New Excel.ApplicationClass
                myApp.Visible = False
                myApp.Workbooks.Open(_strNewExcelPath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
                myBook = myApp.Workbooks(1)
                mySheets = CType(myBook.Worksheets, Excel.Worksheets)//这句出现错误,错误名:specified cast is not valid
                mySheet = CType(mySheets(1), Excel.Worksheet)能帮我分析一下吗
      

  4.   

    Dim myApp As Excel.Application
            Dim myBooks As Excel.Workbooks
            Dim myBook As Excel.Workbook
            Dim mySheet As Excel.Worksheet
            Dim mySheets As Excel.Worksheets
            Dim oMissing As Object
            
                '复制文件
                If File.Exists(_strNewExcelPath) Then
                    File.Delete(_strNewExcelPath)
                End If            File.Copy(_strExcelPath, _strNewExcelPath)
                oMissing = System.Reflection.Missing.Value            myApp = New Excel.ApplicationClass
                myApp.Visible = False            myApp.Workbooks.Open(_strNewExcelPath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
                myBooks = myApp.Workbooks
                myBook = myBooks(1)
                mySheets = myBook.Worksheets  '我又调了一下,现在这句报和上句一样的错误,哪位高手帮忙分析一下啊,我查了好多都是这样写的啊。
                mySheet = CType(mySheets(1), Excel.Worksheet)
      

  5.   

    这块自己搞定了。
    改为            myBook = myApp.Workbooks.Open(_strNewExcelPath, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing)
               
                mySheet = CType(myBook.Sheets(1), Excel.Worksheet)
    这样就通过了。
    另外想问大家一个问题。打开excel文件以后,如何将进程中的关于这个文件的进程杀死
      

  6.   

    如何杀死Word,Excel等进程?
    private void KillProcess(string processName)
    {
    System.Diagnostics.Process myproc= new System.Diagnostics.Process();
    //得到所有打开的进程
        try{
        foreach (Process thisproc in Process.GetProcessesByName(processName)) {
           if(!thisproc.CloseMainWindow()){
    thisproc.Kill();
    }
            }
          }
        catch(Exception Exc)
        {
            msg.Text+= "杀死" + processName + "失败!";
        }
    }