Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.IO;
- using Aspose.Cells;
- namespace AsposeConverter.FileTypes.Office
- {
- public static class Excel
- {
- public static void ToTiff(String input, String output)
- {
- // Configure the print options before doing anything.
- ImageOrPrintOptions printOptions = new ImageOrPrintOptions();
- printOptions.HorizontalResolution = 300;
- printOptions.VerticalResolution = 300;
- printOptions.ImageFormat = ImageFormat.Tiff;
- printOptions.TiffCompression = TiffCompression.CompressionCCITT4;
- printOptions.PrintingPage = PrintingPageType.IgnoreBlank;
- // Create a new workbook to use.
- Workbook book = new Workbook();
- // Open the input file.
- book.Open(input);
- book.ShowTabs = true;
- foreach (Worksheet sheet in book.Worksheets)
- {
- Console.WriteLine(" - Processing sheet #{0} ({1})", sheet.Index, sheet.Name);
- // Sheet options
- sheet.IsVisible = true;
- // Unhide/Ungroup rows and columns
- foreach (Row row in sheet.Cells.Rows)
- sheet.Cells.UnhideRow(row.Index, 1);
- foreach (Column column in sheet.Cells.Columns)
- sheet.Cells.UnhideColumn(column.Index, 1);
- // Sheet settings
- sheet.AutoFitColumns();
- sheet.AutoFitRows();
- sheet.PageSetup.BlackAndWhite = true;
- sheet.PageSetup.PrintComments = PrintCommentsType.PrintNoComments;
- sheet.PageSetup.PrintErrors = PrintErrorsType.PrintErrorsDisplayed;
- sheet.PageSetup.Zoom = 80;
- sheet.PageSetup.Orientation = PageOrientationType.Landscape;
- Cell cell = sheet.Cells[sheet.Cells.MaxDataRow, sheet.Cells.MaxDataColumn];
- sheet.PageSetup.PrintArea = "A1:" + cell.Name;
- }
- WorkbookRender wbr = new WorkbookRender(book, printOptions);
- wbr.ToImage(String.Format(@"{0}\{1}.tiff", output, Path.GetFileNameWithoutExtension(input)));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement