c#使用spire 把word、excel、pdf、ppt转图片

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spire.Pdf;
using Spire.Xls;
using Spire.Doc;
using Spire.Presentation;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //excel 转 图片
        private void button1_Click(object sender, EventArgs e)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"D:\\Production.xlsx", ExcelVersion.Version97to2003);//兼容xlsx版本
            for (int i = 0; i < workbook.Worksheets.Count; i++) {
                Worksheet sheet = workbook.Worksheets[i];
                sheet.SaveToImage(@"D:\\excel"+i+".png");
            }
                
        }
        //word 转 图片
        private void button2_Click_1(object sender, EventArgs e)
        {
            Document document = new Document();
            document.LoadFromFile(@"D:\\doc.docx");
            for (int i = 0; i < document.PageCount; i++)
            {
                Image img = document.SaveToImages(i, Spire.Doc.Documents.ImageType.Metafile);
                img.Save(@"D:\\doc"+i.ToString() + ".png");
            }
            
            
        }
        //pdf 转 图片
        private void button3_Click_1(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();
            
            doc.LoadFromFile(@"D:\\pdf.pdf");
            for (int i = 0; i < doc.Pages.Count; i++) {
                Image bmp = doc.SaveAsImage(i);
                bmp.Save(@"D:\\pdf"+i+".bmp");
            }
                
        }
        //ppt 转 图片
        private void button4_Click(object sender, EventArgs e)
        {
            Presentation presentation = new Presentation();
            presentation.LoadFromFile(@"D:\\ppt.pptx");
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                Image image = presentation.Slides[i].SaveAsImage();
                String fileName = String.Format(@"D:\\图{0}.png", i);
                image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
            }
        }
    }
}

下面是sprie office资源链接,无水印但有页数限制
https://download.csdn.net/download/qq_42016346/12546210

-----------------------------------------------------------------我是分割线--------------------------------------------------------------

看完了觉得不错就点个赞或者评论下吧,感谢!!!

如果本文哪里有误随时可以提出了,收到会尽快更正的
 

你可能感兴趣的:(C#)