English 中文(简体)
将 OpenOffice Calc 文件导出到 PDF 时, 我如何尊重打印区?
原标题:How do I honor the print area when exporting OpenOffice Calc files to PDF?

< a href=" "https://stackoverflow.com/ questions/781191/ saving-to-pdf-from-openoffice/" >这里 有一个将 OpenOffice 文件保存到 PDF 的例子。 I m 使用类似的代码将 Calc 文件保存到 PDF 。 (这足以将属性 writer_pdf_Export 更改为 calc_pdf_Export 。 )

不幸的是,代码没有考虑到原始文件中界定的打印区域。

我怎样才能做到呢?

最佳回答

正在扩展我先前的代码( 它可能不够干净 ), 我会尝试类似的方法( 注意我还没有测试过它 ) 。 第三个参数指定出口区域为 < code> TRect 变量 :

procedure ExportCalcRangeToPDF(const ASourceFileURL, ATargetFileURL: string;
  ASheetIndex: Integer; ARange: TRect);
var
  CellRange: Variant;
  StarOffice: Variant;
  StarDesktop: Variant;
  StarDocument: Variant;
  FilterParams: Variant;
  ExportParams: Variant;
  ExportObject: Variant;

  function CreateProperty(const AName: AnsiString; const AValue: Variant): Variant;
  begin
    Result := StarOffice.Bridge_GetStruct( com.sun.star.beans.PropertyValue );
    Result.Name := AName;
    Result.Value := AValue;
  end;

begin
  StarOffice := CreateOleObject( com.sun.star.ServiceManager );
  StarDesktop := StarOffice.CreateInstance( com.sun.star.frame.Desktop );

  FilterParams := VarArrayCreate([0, 0], varVariant);
  FilterParams[0] := CreateProperty( Hidden , True);

  StarDocument := StarDesktop.LoadComponentFromURL(ASourceFileURL,  _blank , 0,
    FilterParams);
  CellRange := StarDocument.Sheets.getByIndex(ASheetIndex).getCellRangeByPosition(
    ARange.Left, ARange.Top, ARange.Right, ARange.Bottom);

  ExportParams := VarArrayCreate([0, 0], varVariant);
  ExportParams[0] := CreateProperty( Selection , CellRange);

  ExportObject := StarOffice.Bridge_GetValueObject;
  ExportObject.Set( []com.sun.star.beans.PropertyValue , ExportParams);

  FilterParams := VarArrayCreate([0, 1], varVariant);
  FilterParams[0] := CreateProperty( FilterName , AnsiString( calc_pdf_Export ));
  FilterParams[1] := CreateProperty( FilterData , ExportObject);

  StarDocument.StoreToURL(ATargetFileURL, FilterParams);

  StarDocument.Close(True);
  StarDesktop.Terminate;

  StarDocument := Unassigned;
  StarDesktop := Unassigned;
  StarOffice := Unassigned;
end;    

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExportCalcRangeToPDF(
     file:///C:/SourceFile.ods ,
     file:///C:/TargetFile.pdf ,
    0,
    Rect(1, 1, 2, 2)
  );
end;
问题回答

为了获得电子表格的打印区域,我这样做。 (可实施,当然)

  ...
  Sheet: Variant;
  PrintAreas: Variant;
  ...

  ...
  Sheet := StarDocument.Sheets.getByIndex(0); // get the first sheet
  PrintAreas := Sheet.getPrintAreas; // get print areas

  CellRange := Sheet.getCellRangeByPosition(PrintAreas[0].StartColumn,
        PrintAreas[0].StartRow, PrintAreas[0].EndColumn,
        PrintAreas[0].EndRow); // Get range of the first print area
  ...




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签