Hi all,
I am using Aspose Cells .NET 5.2.2.5 to convert excel worksheets that contains charts to PNG image.
The problem is : Chinese charset is not correctly converted in the chart legend. See the horizontal axis of the second chart in the image attached.
Any ideas ?
You will find below the source code and attached the excel source file and the image generated.
Thanks for help,
This is the source code :
public string GenerateImageFromXls(string xlsPath, string sheetId, int horizontalResolution, int verticalResolution)
{
//Instantiate an instance of license and set the license file through its path
Aspose.Cells.License license = new Aspose.Cells.License();
license.SetLicense(ParametresConfiguration.AsposeCellsLicenseFilePath);
if (!string.IsNullOrEmpty(xlsPath))
{
Workbook book = new Workbook();
book.Open(xlsPath);
try
{
book.CalculateFormula(true);
}
catch
{
}
Worksheet sheet = book.Worksheets[sheetId];
//string maxCellName = GetMaxCellName(sheet);
//sheet.PageSetup.PrintArea = "A1:" + maxCellName;
sheet.PageSetup.SetFooter(0, string.Empty);
sheet.PageSetup.SetFooter(1, string.Empty);
sheet.PageSetup.SetFooter(2, string.Empty);
sheet.PageSetup.PaperSize = PaperSizeType.PaperCSheet;
sheet.PageSetup.CenterHorizontally = false;
sheet.PageSetup.CenterVertically = false;
sheet.PageSetup.LeftMargin = 0.0;
sheet.PageSetup.RightMargin = 0.0;
sheet.PageSetup.BottomMargin = 0.0;
sheet.PageSetup.TopMargin = 0.0;
sheet.PageSetup.FooterMargin = 0.0;
sheet.PageSetup.HeaderMargin = 0.0;
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
imgOptions.ImageFormat = ImageFormat.Png;
imgOptions.IsImageFitToPage = true;
imgOptions.HorizontalResolution = horizontalResolution;
imgOptions.VerticalResolution = verticalResolution;
imgOptions.OnePagePerSheet = true;
SheetRender sheetRender = new SheetRender(sheet, imgOptions);
string imagePath = xlsPath.Replace(".xls", string.Empty);
imagePath = string.Format("{0}_{1}.png", imagePath,
sheetId.Replace(" ", "_").Replace("&", "and").Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "")
.Replace("\"", "").Replace("<", "").Replace(">", "").Replace("|", ""));
sheetRender.ToImage(0, imagePath);
return imagePath.Replace("\\", "/");
}
return null;
}