Word输出图片
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) ;
}