Aspose使用

Word输出图片 


OpenFileDialog resultsDatadialog = new OpenFileDialog();
            resultsDatadialog.Filter = "所有Word文档(*.doc,*.docx)|*.doc;*.docx";
            if (resultsDatadialog.ShowDialog() == DialogResult.OK)
            {
                Aspose.Words.Document doc = new Aspose.Words.Document(resultsDatadialog.FileName);


                String dllpath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                dllpath = dllpath.Substring(8, dllpath.Length - 8);    // 8是 file:// 的长度
                string path = System.IO.Path.GetDirectoryName(dllpath) + @"\exTemp";


                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string pdfPath = path + @"\" + Path.GetFileNameWithoutExtension(resultsDatadialog.SafeFileName) + ".jpeg";


                doc.Save(pdfPath, Aspose.Words.SaveFormat.Jpeg);
            }


Excel输出图片


OpenFileDialog resultsDatadialog = new OpenFileDialog();
            resultsDatadialog.Filter = "所有Excel文档(*.xls,*.xlsx)|*.xls;*.xlsx";
            if (resultsDatadialog.ShowDialog() == DialogResult.OK)
            {
                Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(resultsDatadialog.FileName);


                string path = Tool.GetCurDirectory() + @"\exTemp";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string pdfPath = path + @"\"+Path.GetFileNameWithoutExtension(resultsDatadialog.SafeFileName) /*+ ".pdf"*/;


                // Create an object for ImageOptions
                ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
                // Set the format type of the image
                imgOptions.ImageFormat = ImageFormat.Jpeg;


                //CellsHelper.("c:\\windows\\fonts");


                for (int i = 0; i < wb.Worksheets.Count; i++)
                {
                    // Get the worksheet.
                    Worksheet sheet = wb.Worksheets[i];


                    // Create a SheetRender object with respect to your desired sheet
                    SheetRender sr = new SheetRender(sheet, imgOptions);
                    for (int j = 0; j < sr.PageCount; j++)
                    {
                        // Generate image(s) for the worksheet
                        sr.ToImage(j, pdfPath+"sheet_" + i + "_page_" + j + ".jpg");
                    }
                }
            }



 public static String GetCurDirectory()

String dllpath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
                dllpath = dllpath.Substring(8, dllpath.Length - 8);    // 8是 file:// 的长度

 return  System.IO.Path.GetDirectoryName(dllpath) ;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值