Advertisement
Guest User

warz

a guest
Apr 27th, 2010
256
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Drawing;
  3. using System.Drawing.Imaging;
  4. using System.IO;
  5.  
  6. using Aspose.Cells;
  7.  
  8. namespace AsposeConverter.FileTypes.Office
  9. {
  10.     public static class Excel
  11.     {
  12.         public static void ToTiff(String input, String output)
  13.         {
  14.             // Configure the print options before doing anything.
  15.             ImageOrPrintOptions printOptions = new ImageOrPrintOptions();
  16.             printOptions.HorizontalResolution = 300;
  17.             printOptions.VerticalResolution = 300;
  18.             printOptions.ImageFormat = ImageFormat.Tiff;
  19.             printOptions.TiffCompression = TiffCompression.CompressionCCITT4;
  20.             printOptions.PrintingPage = PrintingPageType.IgnoreBlank;
  21.  
  22.             // Create a new workbook to use.
  23.             Workbook book = new Workbook();
  24.  
  25.             // Open the input file.
  26.             book.Open(input);
  27.             book.ShowTabs = true;
  28.  
  29.             foreach (Worksheet sheet in book.Worksheets)
  30.             {
  31.                 Console.WriteLine(" - Processing sheet #{0} ({1})", sheet.Index, sheet.Name);
  32.  
  33.                 // Sheet options
  34.                 sheet.IsVisible = true;
  35.  
  36.                 // Unhide/Ungroup rows and columns
  37.                 foreach (Row row in sheet.Cells.Rows)
  38.                     sheet.Cells.UnhideRow(row.Index, 1);
  39.  
  40.                 foreach (Column column in sheet.Cells.Columns)
  41.                     sheet.Cells.UnhideColumn(column.Index, 1);
  42.  
  43.                 // Sheet settings
  44.                 sheet.AutoFitColumns();
  45.                 sheet.AutoFitRows();
  46.                 sheet.PageSetup.BlackAndWhite = true;
  47.                 sheet.PageSetup.PrintComments = PrintCommentsType.PrintNoComments;
  48.                 sheet.PageSetup.PrintErrors = PrintErrorsType.PrintErrorsDisplayed;
  49.                 sheet.PageSetup.Zoom = 80;
  50.                 sheet.PageSetup.Orientation = PageOrientationType.Landscape;
  51.  
  52.                 Cell cell = sheet.Cells[sheet.Cells.MaxDataRow, sheet.Cells.MaxDataColumn];
  53.                 sheet.PageSetup.PrintArea = "A1:" + cell.Name;
  54.             }
  55.    
  56.             WorkbookRender wbr = new WorkbookRender(book, printOptions);
  57.             wbr.ToImage(String.Format(@"{0}\{1}.tiff", output, Path.GetFileNameWithoutExtension(input)));
  58.         }
  59.     }
  60. }
Advertisement
RAW Paste Data Copied
Advertisement