| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2384 人关注过本帖
标题:如何将 EXCEL 文件转换成图片
取消只看楼主 加入收藏
听水吟
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-9-16
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:4 
如何将 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
搜索更多相关主题的帖子: 运行图 EXCEL 图片 如何 
2014-09-16 15:33
听水吟
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-9-16
收藏
得分:0 
回复 3 楼 风吹过 b
我也怀疑是不是应该是C的语句,要不怎么出现这么多错误,是我把它改成两句的它的原句是:
 Dim app As Microsoft.Office.Interop.Excel.Application = New Microsoft.Office.Interop.Excel.Application()

Dim singleExcel As Microsoft.Office.Interop.Excel.Workbook = app.Workbooks.Open(excelFilePath, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis, objMis)


Dim wsheet As Microsoft.Office.Interop.Excel.Worksheet = singleExcel.Worksheets(1)

我把它拆成两句,不然有错误显红色
2014-09-17 15:30
听水吟
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-9-16
收藏
得分:0 
回复 3 楼 风吹过 b
try
......
      catch
......
end try

这个VB里好像有吧,网上有查到有这种用法,但我也不知道哪里有问题,这段程序中catch 和end try也出错
2014-09-17 15:33
听水吟
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-9-16
收藏
得分:0 
把这段程序放在VB里是这样的
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
        
       (1)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
          (2)myBitmap=New Bitmap(bits.Width,bits.Height)
            
            Dim g As Graphics
            g = Graphics.FromImage(myBitmap)
            
            (3)g.DrawImage(bits,0,0)
            
            (4)myBitmap.Save(String.Format(SaveExcelJPG, Guid.NewGuid()))
            
            (5)Clipboard.Clear()
            
            (6)myBitmap.Dispose()
            
            (7)bits.Dispose()
            
            (8)Return ""
            
        (9)Catch ex As Exception
            ' KillProcess("EXCEL")
            (10)Return ex.Message
        Finally
           (11) Clipboard.Clear()
            ' KillProcess("EXCEL")
        (12)End Try
    End Function

前面两个的错误是缺少语句结束,(3)缺少=号,(4)缺少(号,(5)(6)(7)(11)缺少=号
(8)缺少结束语句,(9)(10)缺少语句结束,(12)缺少:if或select或sub或function或property或type或with或ENUM或语句结束

2014-09-17 15:48
听水吟
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2014-9-16
收藏
得分:0 
回复 8 楼 风吹过 b
研究了很久,终于搞明白这段程序是,谢谢了!
2014-10-11 15:10
快速回复:如何将 EXCEL 文件转换成图片
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020356 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved