首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

请帮小弟看看,怎样利用Excel 打印不显示Excel文件直接打印

2012-02-08 
请各位大哥帮小弟看看,怎样利用Excel 打印不显示Excel文件直接打印?请各位大哥帮小弟看看,怎样利用Excel

请各位大哥帮小弟看看,怎样利用Excel 打印不显示Excel文件直接打印?
请各位大哥帮小弟看看,怎样利用Excel 打印不显示Excel文件直接打印?

界面调用函数
  Public Sub ProviderPrint(ByVal dsPrintInfor As DataSet)

  Dim strRptPath As String = mcGlobal.GetTplPath
  Try
  dtPDTPackingInvoice = dsPrintInfor
  ExcelApp = New Excel.Application
  '设置Excel初始状态
  ExcelApp.Visible = False
  ExcelApp.AlertBeforeOverwriting = False
  ExcelApp.AskToUpdateLinks = False
  ExcelApp.DisplayAlerts = False

  '打开工作薄
  ExcelWorkBook = ExcelApp.Workbooks.Open(strRptPath + mXltFileName)
  ExcelWorkBook = ExcelApp.ActiveWorkbook
  '打开Sheet
  ExcelWorkSheet = ExcelWorkBook.Sheets("Sheet1")
  '列字段定义
  ColumnValue()
  '打印数据
  ProviderDecreaseSumPrint()

  ExcelApp.Visible = True


  '删除Excel引用
  ExcelWorkSheet = Nothing
  ExcelWorkBook = Nothing
  ExcelApp = Nothing

  '垃圾回收
  GC.Collect()
  Catch ex As Exception
  If Not ExcelApp Is Nothing Then
  ExcelApp.Run("closeExcel")
  ExcelApp = Nothing
  End If
  PubShare.Msg.ShowMsg(2, ex.ToString)
  End Try
  End Sub

'显示数据
  Private Sub PrintProviderDecreaseSum(ByVal dtPDTPackingInvoice As DataSet)
  'Dim i As Integer
  'Dim j As Integer
  Dim PrintHeadInfor As DataTable = dtPDTPackingInvoice.Tables(0)
  Dim PrintHead As DataTable = dtPDTPackingInvoice.Tables(1)

  If PrintHeadInfor.Rows(0)(DataAccess.Business.ProviderScoreDecrTbl_F.PROVIDERID_FIELD) <> "" Then
  '费用卡号
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 2, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(PrintHead.Rows(0)("FeeCardNo"))
  '供应商编码
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 3, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(PrintHeadInfor.Rows(0)(DataAccess.Business.ProviderScoreDecrTbl_F.PROVIDERID_FIELD))
  '供应商名称
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 4, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(PrintHeadInfor.Rows(0)(DataAccess.Business.ProviderScoreDecrTbl_F.PROVIDERNM_FIELD))
  '缴费时间
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 5, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(PrintHeadInfor.Rows(0)(DataAccess.Business.ProviderScoreDecrTbl_F.CREATEDATE_FIELD))

  '缴费项目
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 6, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(PrintHead.Rows(0)("AdjustItem"))

  Dim adjustvalue, curvalue As Decimal
  adjustvalue = Format(CDbl(PrintHeadInfor.Rows(0)(DataAccess.Business.ProviderScoreDecrTbl_F.ADJUSTVALUE_FIELD)), "####0.00")
  curvalue = Format(CDbl(PrintHeadInfor.Rows(0)(DataAccess.Business.ProviderScoreDecrTbl_F.CURVALUE_FIELD)), "####0.00")

  '缴费金额
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 7, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(adjustvalue) + "元"
  '卡内金额
  ExcelWorkSheet.Cells(Li_DetailLinePDTPackingHEAD + 8, 1 + Li_DetailColumnPDTPackingHEAD) = _
  "'" + MCO001.DBNULL2Str(curvalue) + "元"

  End If


  End Sub

[解决办法]

VB.NET code
    ExcelApp.Application.Visible = False   'ExcelApp.ActiveWindow.SelectedSheets.PrintPreview   '转到打印预览模式   ExcelApp.ActiveWindow.SelectedSheets.PrintOut   '直接打印 

热点排行