We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Setting PageSetup.FitToPagesWide to 1 causes an exception on Save

Dear Aspose support,

I have a XLS file that I try to transform to PDF. When I do just plane conversion, it goes OK, but I get my pages cut as my spreadsheet is too wide to fit one page width. When I use your recommendation and set PageSetup.FitToPagesWide=1 I get the next exception when saving the file in PDF format:

Index was outside the bounds of the array.

The input file is attached to this post. Here is my code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

using Aspose.Cells;
using Aspose.Pdf.Kit;

namespace AsposeTest {
class Program {
static void Main(string[] args) {

string inputFile = @“C:\Documents and Settings\ghochman\Desktop\excel\2.xls”;
string outputFile = @“C:\Documents and Settings\ghochman\Desktop\excel\2.pdf”;

Workbook wb = new Workbook();
wb.Open(inputFile);

foreach (Worksheet ws in wb.Worksheets) {
ws.PageSetup.FitToPagesWide = 1;
}

wb.Save(outputFile);
}
}
}

Thanks in advance.

Hi,

Please try the attached version, I have tested with it using your template file and it works fine. Following is my test code:

Sample code:

string inputFile = @“e:\test\2.xls”;
string outputFile = @“e:\test\out2.pdf”;

Workbook wb = new Workbook();
wb.Open(inputFile);

foreach (Worksheet ws in wb.Worksheets)
{
ws.PageSetup.FitToPagesWide = 1;
ws.PageSetup.FitToPagesTall = 0;

}

wb.Save(outputFile);



Amjad,



Thanks for timely response. This fix definitely solves the reported
issue.