public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); string filePath = dataDir + "Template.xlsx"; //Create a workbook object from the template file Workbook book = new Workbook(filePath); //Convert each worksheet into svg format in a single page. ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.SaveFormat = SaveFormat.SVG; imgOptions.OnePagePerSheet = true; //Convert each worksheet into svg format foreach (Worksheet sheet in book.Worksheets) { SheetRender sr = new SheetRender(sheet, imgOptions); for (int i = 0; i < sr.PageCount; i++) { //Output the worksheet into Svg image format sr.ToImage(i, filePath + sheet.Name + i + ".out.svg"); } } }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); string filePath = dataDir + "Template.xlsx"; //Create a workbook object from the template file Workbook book = new Workbook(filePath); //Convert each worksheet into svg format in a single page. ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.SaveFormat = SaveFormat.SVG; imgOptions.OnePagePerSheet = true; //Convert each worksheet into svg format foreach (Worksheet sheet in book.Worksheets) { SheetRender sr = new SheetRender(sheet, imgOptions); for (int i = 0; i < sr.PageCount; i++) { //Output the worksheet into Svg image format sr.ToImage(i, filePath + sheet.Name + i + ".out.svg"); } } }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create workbook object from source file Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx"); // Apply different image or print options var imgOption = new ImageOrPrintOptions(); imgOption.ImageFormat = ImageFormat.Png; imgOption.HorizontalResolution = 200; imgOption.VerticalResolution = 200; imgOption.OnePagePerSheet = true; // Apply transparency to the output image imgOption.Transparent = true; // Create image after apply image or print options var sr = new SheetRender(wb.Worksheets[0], imgOption); dataDir = dataDir+ "output.png"; sr.ToImage(0, dataDir); // ExEnd:1 Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); string filePath = dataDir+ "aspose-sample.xlsx"; // Create workbook from source file. Workbook workbook = new Workbook(filePath); // Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Set the print area with your desired range worksheet.PageSetup.PrintArea = "E12:H16"; // Set all margins as 0 worksheet.PageSetup.LeftMargin = 0; worksheet.PageSetup.RightMargin = 0; worksheet.PageSetup.TopMargin = 0; worksheet.PageSetup.BottomMargin = 0; // Set OnePagePerSheet option as true ImageOrPrintOptions options = new ImageOrPrintOptions(); options.OnePagePerSheet = true; options.ImageFormat = ImageFormat.Jpeg; // Take the image of your worksheet SheetRender sr = new SheetRender(worksheet, options); dataDir = dataDir+ "output.out.jpg"; sr.ToImage(0, dataDir); // ExEnd:1 Console.WriteLine("\nProcess completed successfully.\nFile saved at " + dataDir); }
public static void Run() { // ExStart:GenerateDatabarImage // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create workbook object from source excel file Workbook workbook = new Workbook(dataDir + "source.xlsx"); // Access first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Access the cell which contains conditional formatting databar Cell cell = worksheet.Cells["C1"]; // Create and get the conditional formatting of the worksheet int idx = worksheet.ConditionalFormattings.Add(); FormatConditionCollection fcc = worksheet.ConditionalFormattings[idx]; fcc.AddCondition(FormatConditionType.DataBar); // Access the conditional formatting databar DataBar dbar = fcc[0].DataBar; // Create image or print options ImageOrPrintOptions opts = new ImageOrPrintOptions(); opts.ImageFormat = ImageFormat.Png; // Get the image bytes of the databar byte[] imgBytes = dbar.ToImage(cell, opts); // Write image bytes on the disk File.WriteAllBytes(dataDir + "databar_out.png", imgBytes); // ExEnd:GenerateDatabarImage }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open a template excel file Workbook book = new Workbook(dataDir + "Testbook1.xlsx"); // Get the first worksheet. Worksheet sheet = book.Worksheets[0]; // Get the second worksheet. // Worksheet sheet = book.Worksheets[1]; // Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); // Specify the image format imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; // If you want entire sheet as a singe image imgOptions.OnePagePerSheet = true; // Render the sheet with respect to specified image/print options SheetRender sr = new SheetRender(sheet, imgOptions); // Render the image for the sheet Bitmap bitmap = sr.ToImage(0); // Save the image file bitmap.Save(dataDir + "SheetImage_out.jpg"); // ExEnd:1 }
public static void Main() { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Instantiate and open an Excel file Workbook book = new Workbook(dataDir+ "book1.xlsx"); //Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Specify the image format imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; //Set the vertical and horizontal resolution imgOptions.VerticalResolution = 200; imgOptions.HorizontalResolution = 200; //One page per sheet is enabled imgOptions.OnePagePerSheet = true; //Get the first worksheet Worksheet sheet = book.Worksheets[0]; //Render the sheet with respect to specified image/print options SheetRender sr = new SheetRender(sheet, imgOptions); //Render the image for the sheet Bitmap bmp = sr.ToImage(0); //Create a bitmap Bitmap thumb = new Bitmap(100, 100); //Get the graphics for the bitmap System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(thumb); //Draw the image gr.DrawImage(bmp, 0, 0, 100, 100); //Save the thumbnail thumb.Save(dataDir+ "mythumbnail.out.bmp"); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Create a new Workbook object and //open a template Excel file. Workbook book = new Workbook(dataDir + "MyTestBook1.xls"); //Get the first worksheet. Worksheet sheet = book.Worksheets[0]; //Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Specify the image format imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; //Only one page for the whole sheet would be rendered imgOptions.OnePagePerSheet = true; //Render the sheet with respect to specified image/print options SheetRender sr = new SheetRender(sheet, imgOptions); //Render the image for the sheet Bitmap bitmap = sr.ToImage(0); //Save the image file specifying its image format. bitmap.Save(dataDir + "SheetImage.jpg"); // Display result, so that user knows the processing has finished. System.Console.WriteLine("Conversion to Image(s) completed."); }
public static void CreateStaticReport() { //Open template string path = System.Web.HttpContext.Current.Server.MapPath("~"); path = path.Substring(0, path.LastIndexOf("\\")); path += @"\designer\MyTestBook1.xls"; //Instantiate a new Workbook object. Workbook book = new Workbook(path); ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; Worksheet sheet = book.Worksheets[0]; SheetRender sheetRender = new SheetRender(sheet, imgOptions); //Create a memory stream object. MemoryStream memorystream = new MemoryStream(); //Convert worksheet to image. sheetRender.ToImage(0, 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/jpeg"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=SheetImage.jpeg"); HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length); //End response to avoid unneeded html after xls HttpContext.Current.Response.End(); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Create a new Workbook object //Open a template excel file Workbook book = new Workbook(dataDir+ "Testbook.xlsx"); //Get the first worksheet. Worksheet sheet = book.Worksheets[0]; //Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Specify the image format imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; //Render the sheet with respect to specified image/print options SheetRender sr = new SheetRender(sheet, imgOptions); //Render the image for the sheet Bitmap bitmap = sr.ToImage(0); //Save the image file bitmap.Save(dataDir+ "SheetImage.jpg"); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); string filePath = dataDir+ "aspose-sample.xlsx"; //Create workbook from source file. Workbook workbook = new Workbook(filePath); //Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; //Set the print area with your desired range worksheet.PageSetup.PrintArea = "E12:H16"; //Set all margins as 0 worksheet.PageSetup.LeftMargin = 0; worksheet.PageSetup.RightMargin = 0; worksheet.PageSetup.TopMargin = 0; worksheet.PageSetup.BottomMargin = 0; //Set OnePagePerSheet option as true ImageOrPrintOptions options = new ImageOrPrintOptions(); options.OnePagePerSheet = true; options.ImageFormat = ImageFormat.Jpeg; //Take the image of your worksheet SheetRender sr = new SheetRender(worksheet, options); sr.ToImage(0, dataDir+ "output.jpg"); }
public static void Main() { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Instantiate a workbook //Open the template file Workbook book = new Workbook(dataDir+ "MyTestBook1.xlsx"); //Get the first worksheet Worksheet sheet = book.Worksheets[0]; //Specify your print area if you want //sheet.PageSetup.PrintArea = "A1:H8"; //To remove the white border around the image. sheet.PageSetup.LeftMargin = 0; sheet.PageSetup.RightMargin = 0; sheet.PageSetup.BottomMargin = 0; sheet.PageSetup.TopMargin = 0; //Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf; //Set only one page would be rendered for the image imgOptions.OnePagePerSheet = true; imgOptions.PrintingPage = PrintingPageType.IgnoreBlank; //Create the SheetRender object based on the sheet with its //ImageOrPrintOptions attributes SheetRender sr = new SheetRender(sheet, imgOptions); //Convert the image sr.ToImage(0, dataDir+ "img_MyTestBook1.emf"); }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open a template Excel file Workbook workbook = new Workbook(dataDir+ "book1.xls"); // Get the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Get the first Picture in the first worksheet Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[0]; // Set the output image file path string fileName = dataDir+ "aspose-logo.out.Jpg"; string picformat = pic.ImageFormat.ToString(); // Note: you may evaluate the image format before specifying the image path // Define ImageOrPrintOptions ImageOrPrintOptions printoption = new ImageOrPrintOptions(); // Specify the image format printoption.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; // Save the image pic.ToImage(fileName, printoption); // ExEnd:1 Console.WriteLine("\nProcess completed successfully.\nFile saved at " + fileName); }
public static void Run() { // ExStart:ChartRenderingCreatingChart // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Instantiating a Workbook object Workbook workbook = new Workbook(); // Adding a new worksheet to the Workbook int sheetIndex = workbook.Worksheets.Add(); // Obtaining the reference of the newly added worksheet by passing its index to WorksheetCollection Worksheet worksheet = workbook.Worksheets[sheetIndex]; // Adding sample values to cells worksheet.Cells["A1"].PutValue(50); worksheet.Cells["A2"].PutValue(100); worksheet.Cells["A3"].PutValue(150); worksheet.Cells["B1"].PutValue(4); worksheet.Cells["B2"].PutValue(20); worksheet.Cells["B3"].PutValue(50); // Adding a chart to the worksheet int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5); // Accessing the instance of the newly added chart Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; // Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); // ExEnd:ChartRenderingCreatingChart // ExStart:ChartRenderingChartToImage // Converting chart to image chart.ToImage(dataDir + "chartEMF_out.emf", System.Drawing.Imaging.ImageFormat.Emf); // Converting chart to Bitmap System.Drawing.Bitmap bitmap = chart.ToImage(); bitmap.Save(dataDir + "chartBMP_out.bmp", System.Drawing.Imaging.ImageFormat.Bmp); // ExEnd:ChartRenderingChartToImage // ExStart:ChartRenderingChartToImageWithAdvancedOptions // Create an instance of ImageOrPrintOptions and set a few properties ImageOrPrintOptions options = new ImageOrPrintOptions() { VerticalResolution = 300, HorizontalResolution = 300, SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias }; // Convert chart to image with additional settings chart.ToImage(dataDir + "chartPNG_out.png", options); // ExEnd:ChartRenderingChartToImageWithAdvancedOptions // ExStart:ChartRenderingChartToPDF // Converting chart to PDF chart.ToPdf(dataDir + "chartPDF_out.pdf"); // ExEnd:ChartRenderingChartToPDF }
public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create workbook object. Workbook wb = new Workbook(); // Set default font of the workbook to none Style s = wb.DefaultStyle; s.Font.Name = ""; wb.DefaultStyle = s; // Access first worksheet. Worksheet ws = wb.Worksheets[0]; // Access cell A4 and add some text inside it. Cell cell = ws.Cells["A4"]; cell.PutValue("This text has some unknown or invalid font which does not exist."); // Set the font of cell A4 which is unknown. Style st = cell.GetStyle(); st.Font.Name = "UnknownNotExist"; st.Font.Size = 20; st.IsTextWrapped = true; cell.SetStyle(st); // Set first column width and fourth column height ws.Cells.SetColumnWidth(0, 80); ws.Cells.SetRowHeight(3, 60); // Create image or print options. ImageOrPrintOptions opts = new ImageOrPrintOptions(); opts.OnePagePerSheet = true; opts.ImageFormat = ImageFormat.Png; // Render worksheet image with Courier New as default font. opts.DefaultFont = "Courier New"; SheetRender sr = new SheetRender(ws, opts); sr.ToImage(0, "out_courier_new_out.png"); // Render worksheet image again with Times New Roman as default font. opts.DefaultFont = "Times New Roman"; sr = new SheetRender(ws, opts); sr.ToImage(0, "times_new_roman_out.png"); // ExEnd:1 }
static void Main(string[] args) { //Instantiating a Workbook object Workbook workbook = new Workbook("../../data/test.xlsx"); //Create an object for ImageOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Get the first worksheet Worksheet sheet = workbook.Worksheets[0]; //Create a SheetRender object with respect to your desired sheet SheetRender sr = new SheetRender(sheet, imgOptions); //Print the worksheet sr.ToPrinter("Samsung ML-1520 Series"); }
public static void CreateStaticReport() { //Open template string path = System.Web.HttpContext.Current.Server.MapPath("~"); path = path.Substring(0, path.LastIndexOf("\\")); path += @"\designer\MyTestBook1.xls"; //Instantiate a new Workbook object. Workbook book = new Workbook(path); //Get the first worksheet Worksheet sheet = book.Worksheets[0]; //Apply different Image and Print options ImageOrPrintOptions options = new ImageOrPrintOptions(); options.HorizontalResolution = 300; options.VerticalResolution = 300; options.TiffCompression = TiffCompression.CompressionCCITT4; options.IsCellAutoFit = false; options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; options.PrintingPage = PrintingPageType.Default; //Create a memory stream object. MemoryStream memorystream = new MemoryStream(); SheetRender sheetRender = new SheetRender(sheet, options); //Convert worksheet to image. sheetRender.ToTiff(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=SheetImage.tiff"); HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length); //End response to avoid unneeded html after xls HttpContext.Current.Response.End(); }
static void Main(string[] args) { string FilePath = @"..\..\..\Sample Files\"; string FileName = FilePath + "Chart to Image with Image Options.tiff"; //Instantiating a Workbook object Workbook workbook = new Workbook(); //Adding a new worksheet to the Excel object int sheetIndex = workbook.Worksheets.Add(); //Obtaining the reference of the newly added worksheet by //passing its sheet index Worksheet worksheet = workbook.Worksheets[sheetIndex]; //Adding a sample value to "A1" cell worksheet.Cells["A1"].PutValue(50); //Adding a sample value to "A2" cell worksheet.Cells["A2"].PutValue(100); //Adding a sample value to "A3" cell worksheet.Cells["A3"].PutValue(150); //Adding a sample value to "B1" cell worksheet.Cells["B1"].PutValue(4); //Adding a sample value to "B2" cell worksheet.Cells["B2"].PutValue(20); //Adding a sample value to "B3" cell worksheet.Cells["B3"].PutValue(50); //Adding a chart to the worksheet int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5); //Accessing the instance of the newly added chart Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex]; //Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3" chart.NSeries.Add("A1:B3", true); ImageOrPrintOptions options = new ImageOrPrintOptions(); options.HorizontalResolution = 300; options.VerticalResolution = 300; options.TiffCompression = TiffCompression.CompressionLZW; options.IsCellAutoFit = false; options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; options.OnePagePerSheet = true; //Converting chart to image. chart.ToImage(FileName, options); }
static void Main(string[] args) { string MyDir = @"Files\"; //Create a new Workbook object //Open a template excel file Workbook book = new Workbook(MyDir+"Sheet to Image.xls"); //Get the first worksheet. Worksheet sheet = book.Worksheets[0]; //Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Specify the image format imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; //Render the sheet with respect to specified image/print options SheetRender sr = new SheetRender(sheet, imgOptions); //Render the image for the sheet Bitmap bitmap = sr.ToImage(0); //Save the image file bitmap.Save(MyDir+"SheetImage.jpg"); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create workbook object from source file Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx"); //Apply different image or print options var imgOption = new ImageOrPrintOptions(); imgOption.ImageFormat = ImageFormat.Png; imgOption.HorizontalResolution = 200; imgOption.VerticalResolution = 200; imgOption.OnePagePerSheet = true; //Apply transparency to the output image imgOption.Transparent = true; //Create image after apply image or print options var sr = new SheetRender(wb.Worksheets[0], imgOption); sr.ToImage(0, dataDir+ "output.png"); }
public static void Main() { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //Create workbook object from source file Workbook wb = new Workbook(dataDir+ "aspose-sample.xlsx"); //Apply different image or print options var imgOption = new ImageOrPrintOptions(); imgOption.ImageFormat = ImageFormat.Png; imgOption.HorizontalResolution = 200; imgOption.VerticalResolution = 200; imgOption.OnePagePerSheet = true; //Apply transparency to the output image imgOption.Transparent = true; //Create image after apply image or print options var sr = new SheetRender(wb.Worksheets[0], imgOption); sr.ToImage(0, dataDir+ "output.out.png"); }
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(); }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Create a new Workbook object //Open a template excel file Workbook book = new Workbook(dataDir+ "Testbook.xlsx"); //Get the first worksheet. Worksheet sheet = book.Worksheets[0]; //Define ImageOrPrintOptions ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); //Specify the image format imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; //Render the sheet with respect to specified image/print options SheetRender sr = new SheetRender(sheet, imgOptions); //Render the image for the sheet Bitmap bitmap = sr.ToImage(0); //Save the image file bitmap.Save(dataDir+ "SheetImage.jpg"); }
public static void Main() { // The path to the documents directory. string dataDir = Path.GetFullPath("../../../Data/"); //Open a template Excel file Workbook workbook = new Workbook(dataDir+ "book1.xls"); //Get the first worksheet Worksheet worksheet = workbook.Worksheets[0]; //Get the first Picture in the first worksheet Aspose.Cells.Drawing.Picture pic = worksheet.Pictures[0]; //Set the output image file path string fileName = dataDir+ "aspose-logo.Jpg"; string picformat = pic.ImageFormat.ToString(); //Note: you may evaluate the image format before specifying the image path //Define ImageOrPrintOptions ImageOrPrintOptions printoption = new ImageOrPrintOptions(); //Specify the image format printoption.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg; //Save the image pic.ToImage(fileName, printoption); }
public static void CreateStaticReport() { //Instantiating an Workbook object Workbook workbook = new Workbook(); //Obtaining the reference of the newly added worksheet Worksheet sheet = workbook.Worksheets[0]; Cells cells = sheet.Cells; //Setting the value to the cells Aspose.Cells.Cell cell = cells["A1"]; cell.PutValue("Employee"); cell = cells["B1"]; cell.PutValue("Quarter"); cell = cells["C1"]; cell.PutValue("Product"); cell = cells["D1"]; cell.PutValue("Continent"); cell = cells["E1"]; cell.PutValue("Country"); cell = cells["F1"]; cell.PutValue("Sale"); cell = cells["A2"]; cell.PutValue("David"); cell = cells["A3"]; cell.PutValue("David"); cell = cells["A4"]; cell.PutValue("David"); cell = cells["A5"]; cell.PutValue("David"); cell = cells["A6"]; cell.PutValue("James"); cell = cells["A7"]; cell.PutValue("James"); cell = cells["A8"]; cell.PutValue("James"); cell = cells["A9"]; cell.PutValue("James"); cell = cells["A10"]; cell.PutValue("James"); cell = cells["A11"]; cell.PutValue("Miya"); cell = cells["A12"]; cell.PutValue("Miya"); cell = cells["A13"]; cell.PutValue("Miya"); cell = cells["A14"]; cell.PutValue("Miya"); cell = cells["A15"]; cell.PutValue("Miya"); cell = cells["A16"]; cell.PutValue("Miya"); cell = cells["A17"]; cell.PutValue("Miya"); cell = cells["A18"]; cell.PutValue("Elvis"); cell = cells["A19"]; cell.PutValue("Elvis"); cell = cells["A20"]; cell.PutValue("Elvis"); cell = cells["A21"]; cell.PutValue("Elvis"); cell = cells["A22"]; cell.PutValue("Elvis"); cell = cells["A23"]; cell.PutValue("Elvis"); cell = cells["A24"]; cell.PutValue("Elvis"); cell = cells["A25"]; cell.PutValue("Jean"); cell = cells["A26"]; cell.PutValue("Jean"); cell = cells["A27"]; cell.PutValue("Jean"); cell = cells["A28"]; cell.PutValue("Ada"); cell = cells["A29"]; cell.PutValue("Ada"); cell = cells["A30"]; cell.PutValue("Ada"); cell = cells["B2"]; cell.PutValue("1"); cell = cells["B3"]; cell.PutValue("2"); cell = cells["B4"]; cell.PutValue("3"); cell = cells["B5"]; cell.PutValue("4"); cell = cells["B6"]; cell.PutValue("1"); cell = cells["B7"]; cell.PutValue("2"); cell = cells["B8"]; cell.PutValue("3"); cell = cells["B9"]; cell.PutValue("4"); cell = cells["B10"]; cell.PutValue("4"); cell = cells["B11"]; cell.PutValue("1"); cell = cells["B12"]; cell.PutValue("1"); cell = cells["B13"]; cell.PutValue("2"); cell = cells["B14"]; cell.PutValue("2"); cell = cells["B15"]; cell.PutValue("3"); cell = cells["B16"]; cell.PutValue("4"); cell = cells["B17"]; cell.PutValue("4"); cell = cells["B18"]; cell.PutValue("1"); cell = cells["B19"]; cell.PutValue("1"); cell = cells["B20"]; cell.PutValue("2"); cell = cells["B21"]; cell.PutValue("3"); cell = cells["B22"]; cell.PutValue("3"); cell = cells["B23"]; cell.PutValue("4"); cell = cells["B24"]; cell.PutValue("4"); cell = cells["B25"]; cell.PutValue("1"); cell = cells["B26"]; cell.PutValue("2"); cell = cells["B27"]; cell.PutValue("3"); cell = cells["B28"]; cell.PutValue("1"); cell = cells["B29"]; cell.PutValue("2"); cell = cells["B30"]; cell.PutValue("3"); cell = cells["C2"]; cell.PutValue("Maxilaku"); cell = cells["C3"]; cell.PutValue("Maxilaku"); cell = cells["C4"]; cell.PutValue("Chai"); cell = cells["C5"]; cell.PutValue("Maxilaku"); cell = cells["C6"]; cell.PutValue("Chang"); cell = cells["C7"]; cell.PutValue("Chang"); cell = cells["C8"]; cell.PutValue("Chang"); cell = cells["C9"]; cell.PutValue("Chang"); cell = cells["C10"]; cell.PutValue("Chang"); cell = cells["C11"]; cell.PutValue("Geitost"); cell = cells["C12"]; cell.PutValue("Chai"); cell = cells["C13"]; cell.PutValue("Geitost"); cell = cells["C14"]; cell.PutValue("Geitost"); cell = cells["C15"]; cell.PutValue("Maxilaku"); cell = cells["C16"]; cell.PutValue("Geitost"); cell = cells["C17"]; cell.PutValue("Geitost"); cell = cells["C18"]; cell.PutValue("Ikuru"); cell = cells["C19"]; cell.PutValue("Ikuru"); cell = cells["C20"]; cell.PutValue("Ikuru"); cell = cells["C21"]; cell.PutValue("Ikuru"); cell = cells["C22"]; cell.PutValue("Ipoh Coffee"); cell = cells["C23"]; cell.PutValue("Ipoh Coffee"); cell = cells["C24"]; cell.PutValue("Ipoh Coffee"); cell = cells["C25"]; cell.PutValue("Chocolade"); cell = cells["C26"]; cell.PutValue("Chocolade"); cell = cells["C27"]; cell.PutValue("Chocolade"); cell = cells["C28"]; cell.PutValue("Chocolade"); cell = cells["C29"]; cell.PutValue("Chocolade"); cell = cells["C30"]; cell.PutValue("Chocolade"); cell = cells["D2"]; cell.PutValue("Asia"); cell = cells["D3"]; cell.PutValue("Asia"); cell = cells["D4"]; cell.PutValue("Asia"); cell = cells["D5"]; cell.PutValue("Asia"); cell = cells["D6"]; cell.PutValue("Europe"); cell = cells["D7"]; cell.PutValue("Europe"); cell = cells["D8"]; cell.PutValue("Europe"); cell = cells["D9"]; cell.PutValue("Europe"); cell = cells["D10"]; cell.PutValue("Europe"); cell = cells["D11"]; cell.PutValue("America"); cell = cells["D12"]; cell.PutValue("America"); cell = cells["D13"]; cell.PutValue("America"); cell = cells["D14"]; cell.PutValue("America"); cell = cells["D15"]; cell.PutValue("America"); cell = cells["D16"]; cell.PutValue("America"); cell = cells["D17"]; cell.PutValue("America"); cell = cells["D18"]; cell.PutValue("Europe"); cell = cells["D19"]; cell.PutValue("Europe"); cell = cells["D20"]; cell.PutValue("Europe"); cell = cells["D21"]; cell.PutValue("Oceania"); cell = cells["D22"]; cell.PutValue("Oceania"); cell = cells["D23"]; cell.PutValue("Oceania"); cell = cells["D24"]; cell.PutValue("Oceania"); cell = cells["D25"]; cell.PutValue("Africa"); cell = cells["D26"]; cell.PutValue("Africa"); cell = cells["D27"]; cell.PutValue("Africa"); cell = cells["D28"]; cell.PutValue("Africa"); cell = cells["D29"]; cell.PutValue("Africa"); cell = cells["D30"]; cell.PutValue("Africa"); cell = cells["E2"]; cell.PutValue("China"); cell = cells["E3"]; cell.PutValue("India"); cell = cells["E4"]; cell.PutValue("Korea"); cell = cells["E5"]; cell.PutValue("India"); cell = cells["E6"]; cell.PutValue("France"); cell = cells["E7"]; cell.PutValue("France"); cell = cells["E8"]; cell.PutValue("Germany"); cell = cells["E9"]; cell.PutValue("Italy"); cell = cells["E10"]; cell.PutValue("France"); cell = cells["E11"]; cell.PutValue("U.S."); cell = cells["E12"]; cell.PutValue("U.S."); cell = cells["E13"]; cell.PutValue("Brazil"); cell = cells["E14"]; cell.PutValue("U.S."); cell = cells["E15"]; cell.PutValue("U.S."); cell = cells["E16"]; cell.PutValue("Canada"); cell = cells["E17"]; cell.PutValue("U.S."); cell = cells["E18"]; cell.PutValue("Italy"); cell = cells["E19"]; cell.PutValue("France"); cell = cells["E20"]; cell.PutValue("Italy"); cell = cells["E21"]; cell.PutValue("New Zealand"); cell = cells["E22"]; cell.PutValue("Australia"); cell = cells["E23"]; cell.PutValue("Australia"); cell = cells["E24"]; cell.PutValue("New Zealand"); cell = cells["E25"]; cell.PutValue("S.Africa"); cell = cells["E26"]; cell.PutValue("S.Africa"); cell = cells["E27"]; cell.PutValue("S.Africa"); cell = cells["E28"]; cell.PutValue("Egypt"); cell = cells["E29"]; cell.PutValue("Egypt"); cell = cells["E30"]; cell.PutValue("Egypt"); cell = cells["F2"]; cell.PutValue(2000); cell = cells["F3"]; cell.PutValue(500); cell = cells["F4"]; cell.PutValue(1200); cell = cells["F5"]; cell.PutValue(1500); cell = cells["F6"]; cell.PutValue(500); cell = cells["F7"]; cell.PutValue(1500); cell = cells["F8"]; cell.PutValue(800); cell = cells["F9"]; cell.PutValue(900); cell = cells["F10"]; cell.PutValue(500); cell = cells["F11"]; cell.PutValue(1600); cell = cells["F12"]; cell.PutValue(600); cell = cells["F13"]; cell.PutValue(2000); cell = cells["F14"]; cell.PutValue(500); cell = cells["F15"]; cell.PutValue(900); cell = cells["F16"]; cell.PutValue(700); cell = cells["F17"]; cell.PutValue(1400); cell = cells["F18"]; cell.PutValue(1350); cell = cells["F19"]; cell.PutValue(300); cell = cells["F20"]; cell.PutValue(500); cell = cells["F21"]; cell.PutValue(1000); cell = cells["F22"]; cell.PutValue(1500); cell = cells["F23"]; cell.PutValue(1500); cell = cells["F24"]; cell.PutValue(1600); cell = cells["F25"]; cell.PutValue(1000); cell = cells["F26"]; cell.PutValue(1200); cell = cells["F27"]; cell.PutValue(1300); cell = cells["F28"]; cell.PutValue(1500); cell = cells["F29"]; cell.PutValue(1400); cell = cells["F30"]; cell.PutValue(1000); //Set Page Orientation sheet.PageSetup.Orientation = PageOrientationType.Portrait; //Set Paper Size sheet.PageSetup.PaperSize = PaperSizeType.PaperA4; //Show Headings sheet.PageSetup.PrintHeadings = true; //Set Print Area sheet.PageSetup.PrintArea = "A1:C30,D1:F30"; //Create a memory stream object. MemoryStream memorystream = new MemoryStream(); ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; SheetRender sheetRender = new SheetRender(sheet, imgOptions); //Convert worksheet to image. sheetRender.ToTiff(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=SheetImage.tiff"); HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length); //End response to avoid unneeded html after xls HttpContext.Current.Response.End(); }
public void CreateStaticReport() { //Open template string path = System.Web.HttpContext.Current.Server.MapPath("~"); path = path.Substring(0, path.LastIndexOf("\\")); string outpath = path; path += @"\designer\ProductList.xls"; outpath += @"\designer\Output\"; //Lnks will be used to get the output files for later use ArrayList lnks = new ArrayList(); //Create a workbook object from the template file Workbook book = new Workbook(path); //Convert each worksheet into svg format in a single page. ImageOrPrintOptions imgOptions = new ImageOrPrintOptions(); imgOptions.SaveFormat = SaveFormat.SVG; imgOptions.OnePagePerSheet = true; //Convert each worksheet into svg format foreach (Worksheet worksheet in book.Worksheets) { SheetRender sr = new SheetRender(worksheet, imgOptions); for (int i = 0; i < sr.PageCount; i++) { string svgFileName = "ProductList" + worksheet.Index + i + ".svg"; lnks.Add(svgFileName); //Output the worksheet into Svg format sr.ToImage(i, outpath + svgFileName); } } //Show links to all output svg files Literal ltr=new Literal(); ltr.Text="<ul>"; outPanel.Controls.Add(ltr); foreach (string lnk in lnks) { ltr = new Literal(); ltr.Text = "<li>"; outPanel.Controls.Add(ltr); HyperLink hyp = new HyperLink(); hyp.ID = lnk; hyp.Text = lnk; ; hyp.NavigateUrl = "~/designer/Output/" + lnk; outPanel.Controls.Add(hyp); ltr = new Literal(); ltr.Text = "</li>"; outPanel.Controls.Add(ltr); } ltr = new Literal(); ltr.Text = "</ul>"; outPanel.Controls.Add(ltr); }
/// <summary> /// Excel转为图片 /// </summary> /// <param name="source">源文件路径</param> /// <param name="target">图片保存的文件夹路径</param> /// <param name="dpi">dpi</param> /// <param name="format">图片格式</param> public static bool ConverToImage(string source, string target, int resolution = 300, AsposeConvertDelegate d = null) { double percent = 0.0; int page = 0; int total = 0; double second = 0; string path = ""; string message = ""; DateTime startTime = DateTime.Now; if (!FileUtil.CreateDirectory(target)) { throw new DirectoryNotFoundException(); } if (!File.Exists(source)) { throw new FileNotFoundException(); } if (d != null) { second = (DateTime.Now - startTime).TotalSeconds; percent = 0.1; message = "正在解析文件!"; d.Invoke(percent, page, total, second, path, message); } LoadOptions loadOptions = new LoadOptions(LoadFormat.Auto); Workbook workbook = new Workbook(source, loadOptions); total = workbook.Worksheets.Count; if (d != null) { second = (DateTime.Now - startTime).TotalSeconds; percent = 0.2; message = "开始转换文件,共" + total + "页!"; d.Invoke(percent, page, total, second, path, message); } logger.Info("ConverToImage - source=" + source + ", target=" + target + ", pageCount=" + total); for (page = 0; page < total; page++) { Worksheet sheet = workbook.Worksheets[page]; ImageOrPrintOptions op = new ImageOrPrintOptions(); op.ImageFormat = ImageFormat.Png; op.HorizontalResolution = resolution; op.VerticalResolution = resolution; SheetRender sr = new SheetRender(sheet, op); for (int j = 0; j < sr.PageCount; j++ ) { Bitmap bitmap = sr.ToImage(j); path = target + "\\" + (page + 1) + "_" + (j + 1) + ".png"; bitmap.Save(path); if (d != null) { second = (DateTime.Now - startTime).TotalSeconds; percent = 0.2 + (page + 1) * 0.8 / total; message = "正在转换第" + (page + 1) + "/" + total + "页!"; d.Invoke(percent, (page + 1), total, second, path, message); } } } return true; }
public static void Run() { // ExStart:CreateWorkbook // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Create an instance of Workbook in XLSX format Workbook workbook = new Workbook(FileFormatType.Xlsx); // Access the first worksheet Worksheet worksheet = workbook.Worksheets[0]; // Add two columns of data worksheet.Cells["A1"].PutValue("Retail"); worksheet.Cells["A2"].PutValue("Services"); worksheet.Cells["A3"].PutValue("Info & Communication"); worksheet.Cells["A4"].PutValue("Transport Equip"); worksheet.Cells["A5"].PutValue("Construction"); worksheet.Cells["A6"].PutValue("Other Products"); worksheet.Cells["A7"].PutValue("Wholesale"); worksheet.Cells["A8"].PutValue("Land Transport"); worksheet.Cells["A9"].PutValue("Air Transport"); worksheet.Cells["A10"].PutValue("Electric Appliances"); worksheet.Cells["A11"].PutValue("Securities"); worksheet.Cells["A12"].PutValue("Textiles & Apparel"); worksheet.Cells["A13"].PutValue("Machinery"); worksheet.Cells["A14"].PutValue("Metal Products"); worksheet.Cells["A15"].PutValue("Cash"); worksheet.Cells["A16"].PutValue("Banks"); worksheet.Cells["B1"].PutValue(10.4); worksheet.Cells["B2"].PutValue(5.2); worksheet.Cells["B3"].PutValue(6.4); worksheet.Cells["B4"].PutValue(10.4); worksheet.Cells["B5"].PutValue(7.9); worksheet.Cells["B6"].PutValue(4.1); worksheet.Cells["B7"].PutValue(3.5); worksheet.Cells["B8"].PutValue(5.7); worksheet.Cells["B9"].PutValue(3); worksheet.Cells["B10"].PutValue(14.7); worksheet.Cells["B11"].PutValue(3.6); worksheet.Cells["B12"].PutValue(2.8); worksheet.Cells["B13"].PutValue(7.8); worksheet.Cells["B14"].PutValue(2.4); worksheet.Cells["B15"].PutValue(1.8); worksheet.Cells["B16"].PutValue(10.1); // Create a pie chart and add it to the collection of charts int id = worksheet.Charts.Add(ChartType.Pie, 3, 3, 23, 13); // Access newly created Chart instance Chart chart = worksheet.Charts[id]; // Set series data range chart.NSeries.Add("B1:B16", true); // Set category data range chart.NSeries.CategoryData = "A1:A16"; // Turn off legend chart.ShowLegend = false; // Access data labels DataLabels dataLabels = chart.NSeries[0].DataLabels; // Turn on category names dataLabels.ShowCategoryName = true; // Turn on percentage format dataLabels.ShowPercentage = true; // Set position dataLabels.Position = LabelPositionType.OutsideEnd; // Set separator dataLabels.Separator = DataLablesSeparatorType.Comma; // ExEnd:CreateWorkbook // ExStart:TurnOnLeaderLines // Turn on leader lines chart.NSeries[0].HasLeaderLines = true; // Calculete chart chart.Calculate(); // You need to move DataLabels a little leftward or rightward depending on their position to show leader lines int DELTA = 100; for (int i = 0; i < chart.NSeries[0].Points.Count; i++) { int X = chart.NSeries[0].Points[i].DataLabels.X; // If it is greater than 2000, then move the X position a little right otherwise move the X position a little left if (X > 2000) chart.NSeries[0].Points[i].DataLabels.X = X + DELTA; else chart.NSeries[0].Points[i].DataLabels.X = X - DELTA; } // ExEnd:TurnOnLeaderLines // ExStart:SaveChartInImageAndWorkbookInXLSX // In order to save the chart image, create an instance of ImageOrPrintOptions ImageOrPrintOptions anOption = new ImageOrPrintOptions(); // Set image format anOption.ImageFormat = System.Drawing.Imaging.ImageFormat.Png; // Set resolution anOption.HorizontalResolution = 200; anOption.VerticalResolution = 200; // Render chart to image chart.ToImage(dataDir + "output_out.png", anOption); // Save the workbook to see chart inside the Excel workbook.Save(dataDir + "output_out.xlsx"); // ExEnd:SaveChartInImageAndWorkbookInXLSX }
public static void CreateStaticReport() { //Create a new Workbook. Workbook workbook = new Workbook(); //Get the first worksheet. Worksheet sheet = workbook.Worksheets[0]; //Set the name of worksheet sheet.Name = "ChartSheet"; //Get the cells collection in the sheet. Cells cells = workbook.Worksheets[0].Cells; //Put some values into different cells of the sheet. cells["A1"].PutValue("Region"); cells["A2"].PutValue("France"); cells["A3"].PutValue("Germany"); cells["A4"].PutValue("England"); cells["A5"].PutValue("Sweden"); cells["A6"].PutValue("Italy"); cells["A7"].PutValue("Spain"); cells["A8"].PutValue("Portugal"); cells["B1"].PutValue("Sale"); cells["B2"].PutValue(70000); cells["B3"].PutValue(55000); cells["B4"].PutValue(30000); cells["B5"].PutValue(40000); cells["B6"].PutValue(35000); cells["B7"].PutValue(32000); cells["B8"].PutValue(10000); //Create chart int chartIndex = 0; chartIndex = sheet.Charts.Add(ChartType.Pie, 2, 4, 31, 15); Chart chart = sheet.Charts[chartIndex]; //Set properties of chart title chart.Title.Text = "Sales By Region"; chart.Title.TextFont.Color = System.Drawing.Color.Blue; chart.Title.TextFont.IsBold = true; chart.Title.TextFont.Size = 12; //Set properties of nseries chart.NSeries.Add("B2:B8", true); chart.NSeries.CategoryData = "A2:A8"; chart.NSeries.IsColorVaried = false; for (int i = 0; i < chart.NSeries.Count; i++) { //Set the DataLabels in the chart Aspose.Cells.Charts.DataLabels dataLabels = chart.NSeries[i].DataLabels; dataLabels.Position = LabelPositionType.OutsideEnd; dataLabels.ShowCategoryName = false; dataLabels.ShowValue = false; dataLabels.ShowPercentage = true; dataLabels.ShowLegendKey = false; } //Set the Legend. Legend legend = chart.Legend; legend.Position = LegendPositionType.Left; //Apply different Image and Print options ImageOrPrintOptions options = new ImageOrPrintOptions(); options.HorizontalResolution = 300; options.VerticalResolution = 300; options.TiffCompression = TiffCompression.CompressionLZW; options.IsCellAutoFit = false; options.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff; options.PrintingPage = PrintingPageType.Default; //Create a memory stream object. MemoryStream ms = new MemoryStream(); //Conver the chart to image file. chart.ToImage(ms, options); //Set Response object to stream the image file. byte[] data = ms.ToArray(); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "image/tiff"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=ChartPic.tiff"); HttpContext.Current.Response.OutputStream.Write(data, 0, data.Length); //End response to avoid unneeded html after xls HttpContext.Current.Response.End(); }