Hi Aspose,
I am trying to convert each Excel sheet into PNG file.
However I couldn’t build an application with the script below,
because “ImageOrPrintOptions” class doesn’t seem to have the definition “ImageFormat”.
Could you teach me how to get through this problem?
using System;
using System.IO;
using Aspose.Cells;
using Aspose.Cells.Rendering;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Aspose.Cells.License License_cells = new Aspose.Cells.License();
try
{
License_cells.SetLicense("Aspose.Total.lic");
Console.WriteLine("License set successfully.");
}
catch (Exception e)
{
Console.WriteLine("/nThere was an error setting the license: " + e.Message);
}
Console.WriteLine("Process Starts!");
String filepath = @"indir\input.xlsx";
String filename = Path.GetFileName(filepath);
String Outdir = @"outdir";
ExcelFunc(filepath, filename, Outdir);
static void ExcelFunc(String filepath, String filename, String Outdir)
{
// Make directories
Directory.CreateDirectory(Outdir + "/" + filename);
Workbook workbook = new Workbook(filepath);
// Make all sheets invisible except first worksheet
for (int i = 1; i < workbook.Worksheets.Count; i++)
{
workbook.Worksheets[i].IsVisible = false;
}
for (int j = 0; j < workbook.Worksheets.Count; j++)
{
Worksheet ws = workbook.Worksheets[j];
String sheet_outpath = Outdir + "/" + filename + "/" + ws.Name;
Directory.CreateDirectory(sheet_outpath);
String png_outpath = Outdir + "/" + filename + "/" + ws.Name + "/" + "png";
Directory.CreateDirectory(png_outpath);
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.ImageFormat = System.Drawing.Imaging.ImageFormat.Png;
imgOpt.CheckWorkbookDefaultFont = true;
// imgOpt.DefaultFont = "Times New Roman";
SheetRender sr = new SheetRender(ws, imgOpt);
sr.ToImage(0, png_outpath + "/" + ws.Name + ".png");
}
}
}
}
}