Excel出力CreateObject("Excel.Application")

Dim xlApplication = CreateObject("Excel.Application")
        Dim xlBooks = xlApplication.Workbooks.Add
        Dim xlSheet = xlBooks.Worksheets(1)
        Dim strFilePath = comSaveFileDialog(Me, , , TG.eDIALOGKBN.XLS)
        Dim iCnt As Integer = 0
        //Excel表示
        xlApplication.Visible = False

        xlBooks = xlApplication.Workbooks.Add
        xlSheet = xlBooks.ActiveSheet
        //Excel合并单元格
        xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(1, 2)).Merge(Reflection.Missing.Value)
        //Excel背景颜色
        xlSheet.Cells(1, 1).Interior.Color = System.Drawing.Color.FromArgb(171, 171, 171).ToArgb()
        For Each dr As DataRow In Me.ToriData.Select()
            iCnt += 1
            xlSheet.Cells(iCnt, 1).Value = iCnt
            //Excel对齐设定
            xlSheet.Cells(iCnt, 1).HorizontalAlignment = DL_EXCEL_XLHALIGNRIGHT
            //Excel单元格线
            xlSheet.Cells(iCnt, 1).Borders.LineStyle = 1
        Next

        //xlApplication.Visible = True
        //xlApplication.UserControl = True

        'Excel通知
        xlApplication.DisplayAlerts = False

        'Excel保存
        xlBooks.SaveAs(FileName:=strFilePath, FileFormat:=DL_EXCEL_HOZON)

        'Excel退出
        xlApplication.Quit()

        'COM对象释放
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks)
        System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication)

 

你可能感兴趣的:(.net)