gdqq456gdq 2021-05-18 18:45 采纳率: 0%
浏览 171
已结题

CVI导出EXCEL中的图片

开发环境是Lab Windows CVI,需要通过代码打开EXCEL,并导出该EXCEL中的几张图片到指定文件夹中。需要实现这个功能的代码。

  • 写回答

1条回答 默认 最新

  • 小P聊技术 2021-05-20 13:33
    关注
    using Microsoft.Office.Interop.Excel;
         public static bool Convert(string sourcePath, string targetPath, XlFixedFormatType targetType)
        {
        	 bool result;
        	 object missing = Type.Missing;
        	 Microsoft.Office.Interop.Excel.Application application = null;
        	 Workbook workBook = null;
        	 try
        	 {
        	     application = new Microsoft.Office.Interop.Excel.Application();
        	     object target = targetPath;
        	     object type = targetType;
        	     workBook = application.Workbooks.Open(sourcePath, missing, missing, missing, missing, missing,
        	         missing, missing, missing, missing, missing, missing, missing, missing, missing);
        	
        	     workBook.ExportAsFixedFormat(targetType, target, XlFixedFormatQuality.xlQualityStandard, true, false, missing, missing, missing, missing);
        	     result = true;
        	 }
        	 catch
        	 {
        	     result = false;
        	 }
        	 finally
        	 {
        	     if (workBook != null)
        	     {
        	         workBook.Close(true, missing, missing);
        	         workBook = null;
        	     }
        	     if (application != null)
        	     {
        	         application.Quit();
        	         application = null;
        	     }
        	     GC.Collect();
        	     GC.WaitForPendingFinalizers();
        	     GC.Collect();
        	     GC.WaitForPendingFinalizers();
        	 }
        	 return result;
        }

     

    static void Main(string[] args)
      {
            string excelfilePath = ReadIni(@"c:\\file_important\\inicfg.ini", "INFO_R", "epath", "DefaultName");
            string pdffilePath = ReadIni(@"c:\\file_important\\inicfg.ini", "INFO_R", "ppath", "DefaultName");
    
           //  bool result = Program.Convert("C:\\report.xls", "C:\\测试报告", XlFixedFormatType.xlTypePDF);
            bool result = Program.Convert(excelfilePath, pdffilePath, XlFixedFormatType.xlTypePDF);
            //如果转换成功
            if (result)
            {
               
            }
    
        }
    评论

报告相同问题?

悬赏问题

  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面