Print Area - FlexCel.AspNet.FlexCelAspViewer


I am using FlexCel.AspNet.FlexCelAspViewer to show excel file on HTML page. Having a problem showing Excel files with defined Print Area region. Only part of the excel file is shown - part that defined in the Print Area, but I need to show the whole file.

Is there any way to remove Print_Area settings from Excel file?

Is it possible to configure FlexCelAspViewer to show whole file regardles Print Area settings?

Thank you in advance,



> Is there any way to remove Print_Area settings from Excel file?

Yes, print_area is just named range, and you can delete it like any other named range:
int PrintAreaIndex = xls.FindNamedRange(TXlsNamedRange.GetInternalName(InternalNameRange.Print_Area), xls.ActiveSheet);

>Is it possible to configure FlexCelAspViewer to show whole file regardles Print Area settings?

You can configure the range you want to show, but you will have to calculate it yourself. For example:
AspViewer.HtmlExport.PrintRangeLeft = 1;
AspViewer.HtmlExport.PrintRangeTop = 1;
AspViewer.HtmlExport.PrintRangeRight = xls.ColCount;
AspViewer.HtmlExport.PrintRangeBottom = xls.RowCount;

But note that if you do this, you might not get the full file. FlexCelAspViewer has a very complex algorithm to decide what to print, which includes using print_area if available (because that's what you normally want), but it also checks for many other things.

For example, if you have a file whose last cell is B15, but have an image going from A14 to C16, FlexCelAspViewer will use C16 as the last cell, while (RowCount,ColCount) will still be B15, because this is the last cell with data. Also, if you have an empty yellow column at say column D, FlexCelAspViewer will know it has to print D, because even if the column has no data, a user can see it because it is yellow. But if the column D has different width but the same color, FlexCelAspViewer will not include it, as the user can't see different widths.

For normal sheets, you can use this method 2). But in general, I would recommend to just remove the print area before exporting, because as explained, FlexCelAspViewer does a lot of work to ensure what it exports is what you want to export. (even if in this case it might be going a little too far, by including the print_area that you don't want, but that's the problem of "smart" algorithms).


Thank you very much for the answer. 

Looks like the first method is OK. One thing: after I removed Print Area I still see the difference between RowCount and shown file. 

As said, FlexCelAspNetViewer (like any other exporting class in FlexCel) might not use the rowcount when deciding what to export, if for example you have an empty row at the end, it will count for RowCount, but FlexCelAspNewViewer knows that row has no data, and not show it. 

Are you not seeing the whole file after removing the print_area?  If so, maybe what happens is that print_area is a local name, you have one per sheet. In the code above I just removed the one in the active sheet:

int PrintAreaIndex = xls.FindNamedRange(TXlsNamedRange.GetInternalName(InternalNameRange.Print_Area), xls.ActiveSheet);

But you might want to remove them all:

for (int sheet = 1; sheet <=xls.SheetCount; sheet++)
int PrintAreaIndex = xls.FindNamedRange(TXlsNamedRange.GetInternalName(InternalNameRange.Print_Area), xls.ActiveSheet);

if (PrintAreaIndex >= 0) xls.DeleteNamedRange(PrintAreaIndex);