如何将 EXCEL 文件转换成图片
如何将EXCEL文件转换成图片,在网上找了一段程序,有很多错误,怎么改?Public Function ConvertExcelTOImage() As String '将EXCEL转换成图片
Dim excelFilePath As String
excelFilePath = "E:\20140814EQ2008_Dll_VB\运行图甲.xls"
Dim SaveExcelJPG As String
SaveExcelJPG = "E:\20140814EQ2008_Dll_VB\1.jpg"
Dim app As Microsoft.Office.Interop.Excel.Application
app = New Microsoft.Office.Interop.Excel.Application
app.CutCopyMode = False
app.Visible = False
Dim objMis As Object=Type.Missing
Dim singleExcel As Microsoft.Office.Interop.Excel.Workbook
singleExcel = app.Workbooks.Open(excelFilePath, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis)
Try
Dim wsheet As Microsoft.Office.Interop.Excel.Worksheet
wsheet = singleExcel.Worksheets(1)
Dim ranobj As Object
ranobj = DBNull.Value
wsheet.Range("A1", "Z106").Copy (ranobj)
Dim iData As IDataObject
iData = Clipboard.GetDataObject()
Dim bits As Bitmap
bits = iData.GetData(DataFormats.Bitmap)
Dim myBitmap As Bitmap
myBitmap=New Bitmap(bits.Width,bits.Height)
Dim g As Graphics
g = Graphics.FromImage(myBitmap)
g.DrawImage(bits,0,0)
myBitmap.Save(String.Format(SaveExcelJPG, Guid.NewGuid()))
Clipboard.Clear()
myBitmap.Dispose()
bits.Dispose()
Return ""
Catch ex As Exception
' KillProcess("EXCEL")
Return ex.Message
Finally
Clipboard.Clear()
' KillProcess("EXCEL")
End Try
End Function