Hi,
When I loaded an Excel file that was originally saved by Aspose and converted it to emf, I noticed the image output was incorrect.
Code:
var workbook = new Workbook(@“test.xlsx”);
var sheet = workbook.Worksheets[0];
sheet.Cells.GetCell(8, 1).Value = “This is a text that has 3 lines test test test test test test test”;
workbook.Save(@“out.xlsx”);
var newWorkbook = new Workbook(@“out.xlsx”);
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
OnePagePerSheet = true,
Transparent = true
};
var newSheet = newWorkbook.Worksheets[0];
SheetRender render = new SheetRender(newSheet, options);
render.ToImage(0, @“out.emf”);
With the above code, I opened out.xlsx using MS Excel and noticed the there are 3 lines of text which looked good, while in the image output converted by Aspose, the output has only one line and the rest of the text disappeared.
I’ve attached the test files and screenshot for your reference. Could you please look into this?
Thanks,
test.zip (21.3 KB)
screenshot.png (10.5 KB)
@ServerSide527,
Thanks for the template file and screenshot.
I noticed the issue with the output image by using your sample code with your template file. Well, you may cope with your issue using a workaround, see the lines of code (in bold) that you may insert, it will work fine:
e.g
Sample code:
var workbook = new Workbook(@“test.xlsx”);
var sheet = workbook.Worksheets[0];
sheet.Cells.GetCell(8, 1).Value = “This is a text that has 3 lines test test test test test test test”;
AutoFitterOptions opts = new AutoFitterOptions();
opts.OnlyAuto = true;
sheet.AutoFitRows(8, 8, opts);
workbook.Save(@“out.xlsx”);
var newWorkbook = new Workbook(@“out.xlsx”);
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
OnePagePerSheet = true,
Transparent = true
};
var newSheet = newWorkbook.Worksheets[0];
SheetRender render = new SheetRender(newSheet, options);
render.ToImage(0, @“out.emf”);
Hope, this helps a bit.
Hi,
Thanks for your suggestions. I understand we can use AutoFitRows() to adjust the height, and OnlyAuto option is to only auto fit on rows without a custom height. I tried the code and it seems working in my case.
However, even without the AutoFitRorws code, when we open the out.xlsx in Excel, the rows are already automatically fitted. While in Aspose, if we don’t apply the code but open the document ‘var newWorkbook = new Workbook(@“out.xlsx”);’, the row height will not be automatically adjust, which may lead to confusion on whether we need to always call AutoFitRorws() manually every time when opening the document.
Is it possible to make the behaviour consistent with Excel, so we don’t need to worry about the auto-fitted rows?
Thanks
@ServerSide527,
Thanks for sharing your concerns.
We need to evaluate it thoroughly. Let me check with concerned developer from product team if we could log a ticket for it to figure it out in the APIs. We will get back to you soon.
@ServerSide527,
I have discussed your issue with the concerned developer from product team. Well, you can always use the following code to load your XLSX/XLSM files with auto-fit rows on of auto height, see the sample code (especially the lines in bold) for your reference. I have tested it and it works fine:
e.g
Sample code:
var workbook = new Workbook("E:\\test2\\image output is wrong\\test.xlsx");
var sheet = workbook.Worksheets[0];
sheet.Cells.GetCell(8, 1).Value = "This is a text that has 3 lines test test test test test test test";
workbook.Save("E:\\test2\\image output is wrong\\out1.xlsx");
var loadOpt = new LoadOptions();
loadOpt.AutoFitterOptions = new AutoFitterOptions
{
OnlyAuto = true
};
var newWorkbook = new Workbook(“E:\test2\image output is wrong\out1.xlsx”, loadOpt);
var options = new ImageOrPrintOptions
{
ImageFormat = ImageFormat.Emf,
OnlyArea = false,
TextRenderingHint = TextRenderingHint.ClearTypeGridFit,
OnePagePerSheet = true,
Transparent = true
};
var newSheet = newWorkbook.Worksheets[0];
SheetRender render = new SheetRender(newSheet, options);
render.ToImage(0, "E:\\test2\\image output is wrong\\out1.emf");
Let us know if you still find any issue.