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)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值