Recent

Author Topic: How do I set the Print Ranges?  (Read 7027 times)

alexs75

  • Full Member
  • ***
  • Posts: 112
How do I set the Print Ranges?
« on: February 12, 2016, 09:59:57 am »
Hi.
How do I set the print area on the page?

I need to do so here - https://help.libreoffice.org/Calc/Edit_Print_Ranges

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How do I set the Print Ranges?
« Reply #1 on: February 12, 2016, 10:48:38 am »
Hey, you guys are doing much more with fpspreadsheet than ever was intended...

Print ranges are not (yet?) implemented in fpspreadsheet.

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: How do I set the Print Ranges?
« Reply #2 on: February 12, 2016, 11:12:38 am »
A good library. And I want to make it even better.  :D
I will wait.

vesyolyi

  • Newbie
  • Posts: 1
Re: How do I set the Print Ranges?
« Reply #3 on: February 12, 2016, 11:59:35 am »
Hi, I need this function too!

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: How do I set the Print Ranges?
« Reply #4 on: February 12, 2016, 12:04:53 pm »
FYI. The print-range is just a text-part of the table definition.

Code: XML  [Select][+][-]
  1.   <office:body>
  2.     <office:spreadsheet>
  3.       <table:table table:name="Sheet1" table:style-name="ta1" table:print-ranges="Sheet1.A2:Sheet1.C2">
  4.         <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
  5.  
So until (or even if) this option is implemented you could unzip your .ods file and change the context.xml yourself (adding the table:print-ranges).

A simple property in fpspreadsheet would, of course, be much easier :)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How do I set the Print Ranges?
« Reply #5 on: February 12, 2016, 03:14:58 pm »
I am involved in some TAChart stuff at the moment and do not want to focus at fpspreadsheet print ranges at the moment. But if somebody could give me a hint on where the print ranges are defined in ods, xlsx and xls (!) I'd be willing to add them. Or a patch would even be better, of course...
« Last Edit: February 12, 2016, 04:19:40 pm by wp »

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: How do I set the Print Ranges?
« Reply #6 on: February 12, 2016, 03:31:48 pm »
For the fpsopendocument.pas it's here:
Code: Pascal  [Select][+][-]
  1. procedure TsSpreadOpenDocWriter.WriteWorksheet(AStream: TStream;
  2.   ASheetIndex: Integer);
  3. begin
  4.   FWorksheet := FWorkbook.GetWorksheetByIndex(ASheetIndex);
  5.  
  6.   // Header
  7.   AppendToStream(AStream, Format(
  8.     '<table:table table:name="%s" table:style-name="ta%d">', [
  9.     FWorkSheet.Name, ASheetIndex+1
  10.   ]));
  11.  
  12.   // columns
  13.   WriteColumns(AStream, FWorkSheet);
  14.  
  15.   // rows and cells
  16.   // The cells need to be written in order, row by row, cell by cell
  17.   if (boVirtualMode in Workbook.Options) then
  18.   begin
  19.     if Assigned(Workbook.OnWriteCellData) then
  20.       WriteVirtualCells(AStream, FWorksheet)
  21.   end else
  22.     WriteRowsAndCells(AStream, FWorksheet);
  23.  
  24.   // Footer
  25.   AppendToStream(AStream,
  26.     '</table:table>');
  27. end;
Like I showed in the previous post the print-range is an attribute of table:table.
Code: XML  [Select][+][-]
  1.  <office:body>
  2.     <office:spreadsheet>
  3.       <table:table table:name="Sheet1" table:style-name="ta1" table:print-ranges="Sheet1.A2:Sheet1.C2">
  4.         <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
  5.  
(So adding  table:print-ranges="Sheet1.A2:Sheet1.C2" to the table:table part)

This is a per worksheet-setting so a PrintRange-property as string could be added where the user could put A2:C2 as range, or something. I haven't tested if the worksheet-name needs to be in there but OpenOffice does save it there. Also... in OpenOffice it's possible to define multiple ranges. Not sure yet how that is presented in the content.xml.

Edit: Multiple ranges are separated by a space in the content.xml. So Ranges could be a TStringList or something.
Code: XML  [Select][+][-]
  1. <table:table table:name="Sheet1" table:style-name="ta1" table:print-ranges="Sheet1.A2:Sheet1.C2 Sheet1.A2:Sheet1.A2 Sheet1.B4:Sheet1.C6">


I haven't dismembered xlsx yet to see where it's defined there.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How do I set the Print Ranges?
« Reply #7 on: February 13, 2016, 06:50:56 pm »
In r4496, fpspreadsheet has basic support for print ranges and repeated header rows/columns for printing. Writing is implemented for xlsx and ods, no reading yet.

There are the related new worksheet methods:
Code: Pascal  [Select][+][-]
  1.   type TsWorksheet = class
  2.     ...
  3.     // Print ranges
  4.     function AddPrintRange(ARow1, ACol1, ARow2, ACol2: Cardinal): Integer; overload;
  5.     function AddPrintRange(const ARange: TsCellRange): Integer; overload;
  6.     function GetPrintRange(AIndex: Integer): TsCellRange;
  7.     function NumPrintRanges: Integer;
  8.     procedure RemovePrintRange(AIndex: Integer);
  9.  
  10.     procedure SetRepeatedPrintCols(AFirstCol: Cardinal; ALastCol: Cardinal = UNASSIGNED_ROW_COL_INDEX);
  11.     procedure SetRepeatedPrintRows(AFirstRow: Cardinal; ALastRow: Cardinal = UNASSIGNED_ROW_COL_INDEX);
  12.     ...
  13.   end;

Note that the visual spreadsheet controls still do not support any printing, so far.

[UPDATE]
Now writing also to BIFF5 and BIFF8 xls formats.
And reading of print ranges from ODS.
« Last Edit: February 14, 2016, 10:51:11 pm by wp »

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: How do I set the Print Ranges?
« Reply #8 on: February 15, 2016, 09:52:49 am »
for ods not work  :(
in  content.xml:
from fpspreadsheet:
Code: XML  [Select][+][-]
  1. <table:table table:name="Page 1" table:style-name="ta1" table:print-ranges="Page 1.B2:Page 1.I38">
from LibreOffice5:
Code: XML  [Select][+][-]
  1. <table:table table:name="Page 1" table:style-name="ta1" table:print-ranges="&apos;Page 1&apos;.B2:&apos;Page 1&apos;.I38">

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: How do I set the Print Ranges?
« Reply #9 on: February 15, 2016, 10:15:57 am »
When using spaces in a tabname the tabname needs to be quoted in the print-range.

Example:
Code: XML  [Select][+][-]
  1. <table:table table:name="Sheet 1" table:style-name="ta1" table:print-ranges="'Sheet 1'.A2:'Sheet 1'.C2 'Sheet 1'.A2:'Sheet 1'.A2 'Sheet 1'.B4:'Sheet 1'.C6">
  2.  

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How do I set the Print Ranges?
« Reply #10 on: February 15, 2016, 10:14:58 pm »
Should be fixed in the new revision which also implements reading of print ranges and repeated print cols/rows for xlsx.

alexs75

  • Full Member
  • ***
  • Posts: 112
Re: How do I set the Print Ranges?
« Reply #11 on: February 16, 2016, 08:01:16 am »
Work normal.
Big thx.  :D

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: How do I set the Print Ranges?
« Reply #12 on: March 05, 2016, 12:47:55 am »
See my note http://forum.lazarus.freepascal.org/index.php/topic,28223.msg204389.html#msg204389 for recent changes related to the print ranges.

 

TinyPortal © 2005-2018