Issue in AutoFitRows settings

Hi,

I am getting "Parameter is not valid" exception while converting Excel document to Image with AutoFitRows option. Please find my code for my reference below.

Workbook wb = null;

wb = new Workbook(fileName);

foreach (Worksheet ws in wb.Worksheets)

{

AutoFitterOptions autoFitterOptions = new AutoFitterOptions();

autoFitterOptions.AutoFitMergedCells = true;

autoFitterOptions.IgnoreHidden = true;

autoFitterOptions.OnlyAuto = true;

sheet.AutoFitRows(autoFitterOptions);

}

WorkbookRender bookRender = new WorkbookRender(_workBook, _printOptions);

bookRender.ToImage(outputFile); //Getting exception in this line

Please guide me to fix this issue.

Thanks,

Dhivya

Hi,

Please try the latest fix: Aspose.Cells for .NET v7.0.4.1

If you still find the issue, give us your template Excel file, we will check it soon.

Thank you.

Hi Amjad,

I am facing same issue in Aspose.Cells.dll version 7.0.4.1. Please find the attached sample file for your reference.

Thanks,

Dhivya

Hi,

I found, your test code is incomplete, can you please provide us your complete test code to replicate the problem.

The code at this post: 350774

e.g

_printOptions where is this variable declared and initialized
sheet where is this variable declared/initialized.

Hi,

Please find complete code below.

Workbook wb = null;

wb = new Workbook(fileName);

foreach (Worksheet ws in wb.Worksheets)

{

AutoFitterOptions autoFitterOptions = new AutoFitterOptions();

autoFitterOptions.AutoFitMergedCells = true;

autoFitterOptions.IgnoreHidden = true;

autoFitterOptions.OnlyAuto = true;

sheet.AutoFitRows(autoFitterOptions);

}

ImageOrPrintOptions tiffOptions;

tiffOptions.HorizontalResolution = 300;

tiffOptions.VerticalResolution = 300;

tiffOptions.PrintingPage = PrintingPageType.Default;

tiffOptions.PrintWithStatusDialog = false;

tiffOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;

tiffOptions.TiffCompression = (Aspose.Cells.Rendering.TiffCompression)base.Compression;

if (base.ColorReduction == ColorMode.BlackAndWhite)

tiffOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionCCITT4;

tiffOptions.IsCellAutoFit = true;

tiffOptions.IsImageFitToPage = true;

WorkbookRender bookRender = new WorkbookRender(_workBook, tiffOptions);

bookRender.ToImage(outputFile); //Getting exception in this line

Thanks,

Dhivya

Hi,

Please change your code.

ImageOrPrintOptions tiffOptions;

to

ImageOrPrintOptions tiffOptions = new ImageOrPrintOptions();

It works fine. Please see the complete code below for your reference.


string fileName = @“F:\Shak-Data-RW\Downloads\HiddenRow.xlsx”;


Workbook wb = null;


wb = new Workbook(fileName);


foreach (Worksheet sheet in wb.Worksheets)

{


AutoFitterOptions autoFitterOptions = new AutoFitterOptions();


autoFitterOptions.AutoFitMergedCells = true;


autoFitterOptions.IgnoreHidden = true;


autoFitterOptions.OnlyAuto = true;


sheet.AutoFitRows(autoFitterOptions);


}


ImageOrPrintOptions tiffOptions = new ImageOrPrintOptions(); ;


tiffOptions.HorizontalResolution = 300;


tiffOptions.VerticalResolution = 300;


tiffOptions.PrintingPage = PrintingPageType.Default;


tiffOptions.PrintWithStatusDialog = false;


tiffOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Tiff;


/tiffOptions.TiffCompression = (Aspose.Cells.Rendering.TiffCompression)base.Compression;

if (base.ColorReduction == ColorMode.BlackAndWhite)

tiffOptions.TiffCompression = Aspose.Cells.Rendering.TiffCompression.CompressionCCITT4;/


tiffOptions.IsCellAutoFit = true;


tiffOptions.IsImageFitToPage = true;


WorkbookRender bookRender = new WorkbookRender(wb, tiffOptions);


bookRender.ToImage(fileName + “.out.jpg”); //Getting exception in this line





Hi,

Let me know what is the relation between autoFitterOptions.IgnoreHidden = true; property and
TiffCompression in ImageOrPrintOptions. If i comment autoFitterOptions.IgnoreHidden = true line if code and uncomment the TiffCompression in ImageOrPrintOptions, it is working fine.

In my requirement I have to apply both the properties.

Thanks,

Dhivya

Hi,

When you will apply ignoreHidden = true, then hidden rows will be ignored when autofit. e.g row 3 in your file will not autofit.

Hi,

And in this case, if row 3 is not showed (ignorehidded = true), then no content will output.

Excel can not print without print content, we output an empty A4 image, this image is not controlled by pagesetup, and compression.

Hi,

In this scenario is there any way to find whether the output image is empty before converting to image.

Thanks,

Dhivya

Hi,

Thanks for your question.

Please use this code to decide, if the output image is empty.

SheetRender sr = new SheetRender(sheet, imgOptions);
if(sr.PageCount ==0) //indicate no output content