aspose将excel的每一个sheet 转换为图片,结果缺少很多文字
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Cells;
using System.IO;using System.Drawing.Imaging;
    class Program
    {
        static void Main(string[] args)
        {
            string excelInputPath = "e:\\1.xlsx";
            string imageOutputPath = "";
           
            if (imageOutputPath.Trim().Length == 0)
            {
                imageOutputPath = Path.GetDirectoryName(excelInputPath)+Path.GetFileNameWithoutExtension(excelInputPath);
            }            Workbook workbook = new Workbook();
            workbook.Open(excelInputPath);
            int i = 0;
            ImageFormat imageFormat = ImageFormat.Jpeg;
            foreach (Worksheet worksheet in workbook.Worksheets)
            {
                if (worksheet.Cells.Rows.Count > 0)
                {
                    worksheet.SheetToImage(imageOutputPath + "_" + i.ToString()+"." + imageFormat,
                    ImageFormat.Jpeg);
                    i++;
                }
            }

解决方案 »

  1.   


     依然不行,我改成了png
    我觉得是否 就不应该用这几个类,谢谢诶你,前几天我问你过你托管c++我不懂C#, 临时学习的,项目需要的我们的要求是: 不要依赖于安装office,就可以把office转换为图片aspose.word可以转化图片,但是 excel似乎转化有问题。 谁能提供一个法子解决
      

  2.   

    参考http://www.cnblogs.com/evgetsolutions/archive/2011/09/05/2167164.html
      

  3.   


    多谢已经解决, emf转换为jpg,能否做到不失真????感觉是不行了, 如果不转换,emf很大, 对于网络传输来说,非常庞大
      

  4.   


    晕倒,仔细看了转换的图片,发现这个代码,只能转换第0个worksheet,其他转换不了.  其他的图片是空的             nPages = 0;               if (!Directory.Exists(imageOutputPath)) { Directory.CreateDirectory(imageOutputPath); }             imageOutputPath = Path.GetDirectoryName(excelInputPath) + Path.GetFileNameWithoutExtension(excelInputPath);
                //Open the template file            Workbook book = new Workbook(excelInputPath);            foreach (Worksheet sheet in book.Worksheets)
                {                //Specify your print area if you want                //sheet.PageSetup.PrintArea = "A1:H8";                //To remove the white border around the image.                sheet.PageSetup.LeftMargin = 0;                sheet.PageSetup.RightMargin = 0;                sheet.PageSetup.BottomMargin = 0;                sheet.PageSetup.TopMargin = 0;                //Define ImageOrPrintOptions                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();                ImageFormat imageFormat = ImageFormat.Emf;                imgOptions.ImageFormat = imageFormat;                //Set only one page would be rendered for the image                imgOptions.OnePagePerSheet = true;                imgOptions.PrintingPage = PrintingPageType.IgnoreBlank;                //Create the SheetRender object based on the sheet with its                //ImageOrPrintOptions attributes                SheetRender sr = new SheetRender(sheet, imgOptions);                //Convert the image
                    sr.ToImage(nPages, imageOutputPath + "_" + nPages.ToString() + "." + imageFormat.ToString());                nPages++;            }
    我做的excel的例子是3个worksheet,结果只有第0个worksheet被转换,按道理是应该转换出3张图片才对。3张图片都不能使空的!!! 现在只有第0个不是空图片
      

  5.   

     调试看看book.Worksheets的个数
                foreach (Worksheet sheet in book.Worksheets)
      

  6.   


    npages是3,也就是说明了, 执行了3次循环。 我对你提供的源码,几乎一直。而且,我也调试过了,确实是3次。程序没有任何异常,没有任何提示错误信息。只是有2个emf文件是空的。
      

  7.   

    初步是怀疑你的aspose版本问题,多找几个版本测试一下,一般官方测试版会有限制,只让你转换一页。
    这里有如何把emf转化为其他格式的方法,http://social.microsoft.com/Forums/de-DE/visualcshartzhchs/thread/67d5b76b-6aef-437c-97cb-739b58a016a6
      

  8.   


    已经找到原因了
     sr.ToImage(nPages
    这个参数,无意发现的。已经解决问题
      

  9.   

    的确,要把nPages这个参数固定为0,否则图片不会继续生成,注意后面的输出文件名中的nPages继续递增,不然后面的文件名都相同就会把前面生成的文件覆盖