4

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

4

4 回答 4

3

您将需要 Aspose.Slides、Aspose.Words、Aspose.Cells 和 Aspose.Pdf,或者您可以使用Web Api

于 2012-11-20T08:45:31.180 回答
2

无需使用任何第三方组件即可完成从办公文档到图像的转换。例如,下面的代码会将特定范围从 Excel 工作表转换为图像。

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

用途:

    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;
    }
于 2013-02-01T08:46:01.480 回答
1

我的名字是 Nayyer,我在 Aspose 担任开发人员布道师。

于 2012-11-26T13:04:22.637 回答
0

我知道现在是 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);
于 2019-05-31T12:47:54.850 回答