Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Aspose将Excel、PowerPoint、PDF和Word转换为.NET中的图像_C#_.net_Vb.net_Aspose - Fatal编程技术网

C# 使用Aspose将Excel、PowerPoint、PDF和Word转换为.NET中的图像

C# 使用Aspose将Excel、PowerPoint、PDF和Word转换为.NET中的图像,c#,.net,vb.net,aspose,C#,.net,Vb.net,Aspose,因此,我正在寻找一种将Excel、PowerPoint、PDF和Word转换为图像的方法。我想知道是否有人有使用Aspose套件的经验,并且知道是否所有这些都可以通过Aspose.PDF套件完成,或者我是否需要获得Aspose.slides和Aspose.word?您将需要Aspose.slides、Aspose.Words、,你也可以使用Aspose.Cells和Aspose.Pdf,我的名字是Nayyer,我是Aspose的开发者福音传道者 Words提供了创建/操作MS word的功能

因此,我正在寻找一种将Excel、PowerPoint、PDF和Word转换为图像的方法。我想知道是否有人有使用Aspose套件的经验,并且知道是否所有这些都可以通过Aspose.PDF套件完成,或者我是否需要获得Aspose.slides和Aspose.word?

您将需要Aspose.slides、Aspose.Words、,你也可以使用Aspose.Cells和Aspose.Pdf,我的名字是Nayyer,我是Aspose的开发者福音传道者

  • Words提供了创建/操作MS word的功能 它还提供了转换word文档的功能 转换为图像格式。您可以查看以下链接以了解有关的更多详细信息 (只需选择Jpeg、Png、Bmp 从SaveFormat枚举)
  • 同样,您可以使用Aspose.Cells将Excel工作表转换为图像格式
  • 幻灯片可用于转换PowerPoint 将演示文稿转换为图像格式
  • Pdf支持将Pdf页面转换为图像的功能 格式。欲了解更多详情,请访问

从office文档到图像的转换可以在不使用任何第三方组件的情况下完成。例如,下面的代码将特定范围从Excel工作表转换为图像

重要提示:不要忘记用[StatThread]属性标记方法

使用:

    using xls = Microsoft.Office.Interop.Excel;
    using System.IO;
    using System.Windows.Forms;
转换代码:

    [STAThread]
    static void Main(string[] args)
    {
        string fileNameToProcess = @"D:\Book2.xlsx";

        //Start Excel and create a new document.
        xls.Application oExcel = new xls.Application();
        xls.Workbook wb = null;
        try
        {
            wb = oExcel.Workbooks.Open(
                fileNameToProcess.ToString(), false, false, Type.Missing, "", "", true, xls.XlPlatform.xlWindows, "", false, false, 0, false, true, 0);
            //wb.RefreshAll();

            xls.Sheets sheets = wb.Worksheets as xls.Sheets;
            xls.Worksheet sheet = sheets[1];

            //Following is used to find range with data
            string startRange = "A1";
            string endRange = "P25";
            xls.Range range = sheet.get_Range(startRange, endRange);
            range.CopyPicture(xls.XlPictureAppearance.xlScreen, xls.XlCopyPictureFormat.xlBitmap);

            System.Drawing.Image imgRange = GetImageFromClipboard();

            imgRange.Save(@"d:\ExcelSheetImage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

            wb.Save();
            Console.Write("Specified range converted to image successfully. Press Enter to continue.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            //throw;
        }
        finally 
        {
            wb.Close();
            oExcel.Quit();
            oExcel = null;
        }

        Console.ReadLine();
    }

    public static System.Drawing.Image GetImageFromClipboard()
    {
        System.Drawing.Image returnImage = null;

        // This doesn't work
        //if (Clipboard.ContainsImage())
        //{
        //    returnImage = Clipboard.GetImage();
        //}
        //return returnImage;

        // This works
        System.Windows.Forms.IDataObject d = Clipboard.GetDataObject();
        if (d.GetDataPresent(DataFormats.Bitmap))
        {
            returnImage = Clipboard.GetImage();
        }

        return returnImage;
    }

我知道现在是2019年,但如果有人还在想,你可以用Aspose.Words来完成

SaveFormat枚举中的以下值(及更多值)可用:

    Tiff = 100,
    //
    // Summary:
    //     Renders a page of the document and saves it as a PNG file.
    Png = 101,
    //
    // Summary:
    //     Renders a page of the document and saves it as a BMP file.
    Bmp = 102,
    //
    // Summary:
    //     Renders a page of the document and saves it as a JPEG file.
    Jpeg = 104,
    //
    // Summary:
    //     Renders a page of the document and saves it as a GIF file.
    Gif = 105
您可以这样使用它们:

    var fileContents = asposeDocument.GenerateDocument(Aspose.Words.SaveFormat.Png);

为什么不把这个问题直接放到aspose论坛上呢?我发了一封支持邮件,但有时候我在这里得到了更快的回复。自从我发现Web API以来,它运行得很好:)感谢Web API的链接,没有我的项目真正不需要的所有额外Aspose功能,更便宜。我会检查一下,我花了几天时间研究使用Interop实现这一点的方法,但无法做到。不久前我问过这个问题,所以我已经编写了所有的代码,但它只是演示版,还没有购买任何东西,所以现在更改还不算晚。PowerPoint教程已移至