public List <Sheet> RenderExcelWorksheetsAsImage(string FileName) { // Load the Excel workbook Workbook book = new Workbook(Server.MapPath(Path.Combine("~/Documents", FileName))); var workSheets = new List <Sheet>(); // Set image rendering options ImageOrPrintOptions options = new ImageOrPrintOptions(); options.HorizontalResolution = 200; options.VerticalResolution = 200; options.AllColumnsInOnePagePerSheet = true; options.OnePagePerSheet = true; options.TextCrossType = TextCrossType.Default; options.ImageType = Aspose.Cells.Drawing.ImageType.Png; string imagePath = ""; string basePath = Server.MapPath("~/"); // Create Excel workbook renderer WorkbookRender wr = new WorkbookRender(book, options); // Save and view worksheets for (int j = 0; j < book.Worksheets.Count; j++) { imagePath = Path.Combine("/Documents/Rendered", string.Format("sheet_{0}.png", j)); wr.ToImage(j, basePath + imagePath); workSheets.Add(new Sheet { SheetName = string.Format("{0}", book.Worksheets[j].Name), Path = imagePath }); } return(workSheets); }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx"); ImageOrPrintOptions opts = new ImageOrPrintOptions(); opts.ImageType = Drawing.ImageType.Tiff; WorkbookRender wr = new WorkbookRender(wb, opts); wr.ToImage(outputDir + "outputUseWorkbookRenderForImageConversion.tiff"); Console.WriteLine("UseWorkbookRenderForImageConversion executed successfully."); }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); //Open an Excel file. Workbook workbook = new Workbook(sourceDir + "sampleSetDefaultFontPropertyOfPdfSaveOptionsAndImageOrPrintOptions.xlsx"); //Rendering to PNG file format while setting the CheckWorkbookDefaultFont attribue to false. //So, "Times New Roman" font would be used for any missing (not installed) font in the workbook. ImageOrPrintOptions imgOpt = new ImageOrPrintOptions(); imgOpt.ImageType = Drawing.ImageType.Png; imgOpt.CheckWorkbookDefaultFont = false; imgOpt.DefaultFont = "Times New Roman"; SheetRender sr = new SheetRender(workbook.Worksheets[0], imgOpt); sr.ToImage(0, outputDir + "out1_imagePNG.png"); //Rendering to TIFF file format while setting the CheckWorkbookDefaultFont attribue to false. //So, "Times New Roman" font would be used for any missing (not installed) font in the workbook. imgOpt.ImageType = Drawing.ImageType.Tiff; WorkbookRender wr = new WorkbookRender(workbook, imgOpt); wr.ToImage(outputDir + "out1_imageTIFF.tiff"); //Rendering to PDF file format while setting the CheckWorkbookDefaultFont attribue to false. //So, "Times New Roman" font would be used for any missing (not installed) font in the workbook. PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.DefaultFont = "Times New Roman"; saveOptions.CheckWorkbookDefaultFont = false; workbook.Save(outputDir + "out1_pdf.pdf", saveOptions); Console.WriteLine("SetDefaultFontPropertyOfPdfSaveOptionsAndImageOrPrintOptions executed successfully.\r\n"); }
public static void Run() { // ExStart:1 //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); Workbook workbook = new Workbook(sourceDir + "sampleUseWorkbookRenderForImageConversion.xlsx"); ImageOrPrintOptions opts = new ImageOrPrintOptions(); opts.PageSavingCallback = new TestTiffPageSavingCallback(); opts.ImageType = ImageType.Tiff; WorkbookRender wr = new WorkbookRender(workbook, opts); wr.ToImage(outputDir + "DocumentConversionProgressForTiff_out.tiff"); // ExEnd:1 Console.WriteLine("DocumentConversionProgressForTiff executed successfully."); }
public static void CreateStaticReport() { //Open template string path = System.Web.HttpContext.Current.Server.MapPath("~"); path = path.Substring(0, path.LastIndexOf("\\")); path += @"\designer\FinancialPlan.xls"; Workbook workbook = new Workbook(path); ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; imgOptions.HorizontalResolution = 100; imgOptions.VerticalResolution = 100; imgOptions.OnePagePerSheet = true; WorkbookRender bookRender = new WorkbookRender(workbook, imgOptions); //Create a memory stream object. MemoryStream memorystream = new MemoryStream(); bookRender.ToImage(memorystream); memorystream.Seek(0, SeekOrigin.Begin); //Set Response object to stream the image file. byte[] data = memorystream.ToArray(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "image/tiff"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=WorkbookImage.tiff"); HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length); //End response to avoid unneeded html after xls HttpContext.Current.Response.End(); }