Hi all,
I am using Aspose Cells .NET 5.2.0.2 to convert excel worksheets that contains charts to PNG image.
The problem is : In the Excel source file there is a hidden column (col M), being hidden, this column does not appear in the chart which is good. However, the column appears in the chart in the image generated.
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} <em>{1}.png", imagePath,
sheetId.Replace(" ", "</em> ").Replace("&", “and”).Replace("\", “”).Replace("/", “”).Replace(":", “”).Replace("*", “”)
.Replace(""", “”).Replace("<", “”).Replace(">", “”).Replace("|", “”));
sheetRender.ToImage(0, imagePath);
return imagePath.Replace("\", “/”);
}
return null;
}
Hi,
I tried using latest version Aspose.Cells for .NET (Latest Version)
I think, it works fine and similar to your MS Excel’s original chart’s preview. I have attached the output file here.
If you still find any difference, kindly do explain where is the issue, you may encircle the affected/issue area and give us the file(s). We will check it soon.
Here is my simplified code using your template file:
Workbook book = new Workbook(“e:\test2\excel_image\PRC_W2-IPCC_20110125_083825_179.xls”);
book.CalculateFormula(true);
Worksheet sheet = book.Worksheets[0];
//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 = 200;
imgOptions.VerticalResolution = 200; ;
imgOptions.OnePagePerSheet = true;
SheetRender sheetRender = new SheetRender(sheet, imgOptions);
//string imagePath = xlsPath.Replace(".xls", string.Empty);
// imagePath = string.Format("{0} <em>{1}.png", imagePath,
// sheetId.Replace(" ", "</em> ").Replace("&", “and”).Replace("\", “”).Replace("/", “”).Replace(":", “”).Replace("*", “”)
// .Replace(""", “”).Replace("<", “”).Replace(">", “”).Replace("|", “”));
sheetRender.ToImage(0, “e:\test2\excel_image\image_excel.png”);
Thank you.
Hi,
Thank you for your quick reply.
The issue is still here.
In general in excel, when I build a chart with several data series, when I hide the column of one serie, it is not shown anymore in the chart. Therefore I expect it not to be in the result image after excel to image convertion.
In my Excel file, I have two “MPT” columns, column M which is hidden in the excel sheet and column P which is displayed. In the chart, I have only one “MPT” serie visible (see the legend), this is because the data corresponding to the other serie is hidden.
In the image generated, I found two “MPT” series in the Chart (see the legend). One that corresponds to the “MTP” serie visible in the chart in the excel file. One corresponding to the data hidden in the excel file. I expected this second serie not to be converted.
Attached is the chart converted with a comment on the issue.
Hi,
Thanks for explaining your issue. I am now able to find the issue as you have described. I have logged your issue into our issue tracking system with an id: CELLSNET-23924. We will figure your issue out soon.
Thank you.
Hi,
We have fixed your issue. Please download the Aspose.Cells for .NET (Latest Version)