You've already forked lazarus-ccr
fpspreadsheet: Simplify clipboard access. Add format "Star Object Descriptor (XML)" for testing communication between LibreOffice and Clipboard.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4368 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1310,7 +1310,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
w := FWorksheet.DefaultColWidth;
|
w := FWorksheet.DefaultColWidth;
|
||||||
col := FWorksheet.FindCol(AColIndex);
|
col := FWorksheet.FindCol(AColIndex);
|
||||||
if col <> nil then
|
if (col <> nil) and (col^.Width > 0) then
|
||||||
w := col^.Width;
|
w := col^.Width;
|
||||||
end;
|
end;
|
||||||
w := w * FWorkbook.GetDefaultFont.Size;
|
w := w * FWorkbook.GetDefaultFont.Size;
|
||||||
|
@ -192,6 +192,7 @@ type
|
|||||||
procedure AddBuiltinNumFormats; override;
|
procedure AddBuiltinNumFormats; override;
|
||||||
procedure CreateStreams;
|
procedure CreateStreams;
|
||||||
procedure DestroyStreams;
|
procedure DestroyStreams;
|
||||||
|
procedure InternalWriteToStream(AStream: TStream);
|
||||||
procedure ListAllColumnStyles;
|
procedure ListAllColumnStyles;
|
||||||
procedure ListAllHeaderFooterFonts;
|
procedure ListAllHeaderFooterFonts;
|
||||||
procedure ListAllNumFormats; override;
|
procedure ListAllNumFormats; override;
|
||||||
@ -233,6 +234,9 @@ type
|
|||||||
procedure WriteToStream(AStream: TStream; AParam: Integer = 0); override;
|
procedure WriteToStream(AStream: TStream; AParam: Integer = 0); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure WriteStarObjectDescriptorToStream(AStream: TStream);
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -354,6 +358,27 @@ type
|
|||||||
end;
|
end;
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
{******************************************************************************}
|
||||||
|
{ Clipboard utility }
|
||||||
|
{******************************************************************************}
|
||||||
|
|
||||||
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
Writes the "Star Object Descriptor". This is written to the clipboard by
|
||||||
|
Open/LibreOffice. No idea about the meaning of this...
|
||||||
|
-------------------------------------------------------------------------------}
|
||||||
|
procedure WriteStarObjectDescriptorToStream(AStream: TStream);
|
||||||
|
const
|
||||||
|
BYTES: packed array[0..$38] of byte = (
|
||||||
|
$39,$00,$00,$00,$CB,$B4,$BB,$47,$4C,$CE,$80,$4E,$A5,$91,$42,$D9,
|
||||||
|
$AE,$74,$95,$0F,$01,$00,$00,$00,$D2,$08,$00,$00,$C4,$01,$00,$00,
|
||||||
|
$00,$00,$00,$00,$00,$00,$00,$00,$05,$00,$63,$61,$6C,$63,$38,$00,
|
||||||
|
$00,$67,$45,$23,$01,$EF,$CD,$AB,$89);
|
||||||
|
begin
|
||||||
|
AStream.Write(BYTES, SizeOf(BYTES));
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{******************************************************************************}
|
{******************************************************************************}
|
||||||
{ TXMLHeaderFooterFont }
|
{ TXMLHeaderFooterFont }
|
||||||
{******************************************************************************}
|
{******************************************************************************}
|
||||||
@ -3657,6 +3682,49 @@ begin
|
|||||||
DestroyStream(FSMetaInfManifest);
|
DestroyStream(FSMetaInfManifest);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadOpenDocWriter.InternalWriteToStream(AStream: TStream);
|
||||||
|
var
|
||||||
|
FZip: TZipper;
|
||||||
|
begin
|
||||||
|
{ Analyze the workbook and collect all information needed }
|
||||||
|
ListAllNumFormats;
|
||||||
|
ListAllColumnStyles;
|
||||||
|
ListAllRowStyles;
|
||||||
|
ListAllHeaderFooterFonts;
|
||||||
|
|
||||||
|
{ Create the streams that will hold the file contents }
|
||||||
|
CreateStreams;
|
||||||
|
|
||||||
|
{ Fill the strings with the contents of the files }
|
||||||
|
WriteMimetype();
|
||||||
|
WriteMetaInfManifest();
|
||||||
|
WriteMeta();
|
||||||
|
WriteSettings();
|
||||||
|
WriteStyles();
|
||||||
|
WriteContent;
|
||||||
|
|
||||||
|
{ Now compress the files }
|
||||||
|
FZip := TZipper.Create;
|
||||||
|
try
|
||||||
|
FZip.FileName := '__temp__.tmp';
|
||||||
|
|
||||||
|
FZip.Entries.AddFileEntry(FSMeta, OPENDOC_PATH_META);
|
||||||
|
FZip.Entries.AddFileEntry(FSSettings, OPENDOC_PATH_SETTINGS);
|
||||||
|
FZip.Entries.AddFileEntry(FSStyles, OPENDOC_PATH_STYLES);
|
||||||
|
FZip.Entries.AddFileEntry(FSContent, OPENDOC_PATH_CONTENT);
|
||||||
|
FZip.Entries.AddFileEntry(FSMimetype, OPENDOC_PATH_MIMETYPE);
|
||||||
|
FZip.Entries.AddFileEntry(FSMetaInfManifest, OPENDOC_PATH_METAINF_MANIFEST);
|
||||||
|
|
||||||
|
ResetStreams;
|
||||||
|
|
||||||
|
FZip.SaveToStream(AStream);
|
||||||
|
|
||||||
|
finally
|
||||||
|
DestroyStreams;
|
||||||
|
FZip.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.ListAllColumnStyles;
|
procedure TsSpreadOpenDocWriter.ListAllColumnStyles;
|
||||||
var
|
var
|
||||||
i, j, c: Integer;
|
i, j, c: Integer;
|
||||||
@ -4764,48 +4832,9 @@ end;
|
|||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.WriteToStream(AStream: TStream;
|
procedure TsSpreadOpenDocWriter.WriteToStream(AStream: TStream;
|
||||||
AParam: Integer = 0);
|
AParam: Integer = 0);
|
||||||
var
|
|
||||||
FZip: TZipper;
|
|
||||||
begin
|
begin
|
||||||
Unused(AParam);
|
Unused(AParam);
|
||||||
|
InternalWriteToStream(AStream);
|
||||||
{ Analyze the workbook and collect all information needed }
|
|
||||||
ListAllNumFormats;
|
|
||||||
ListAllColumnStyles;
|
|
||||||
ListAllRowStyles;
|
|
||||||
ListAllHeaderFooterFonts;
|
|
||||||
|
|
||||||
{ Create the streams that will hold the file contents }
|
|
||||||
CreateStreams;
|
|
||||||
|
|
||||||
{ Fill the strings with the contents of the files }
|
|
||||||
WriteMimetype();
|
|
||||||
WriteMetaInfManifest();
|
|
||||||
WriteMeta();
|
|
||||||
WriteSettings();
|
|
||||||
WriteStyles();
|
|
||||||
WriteContent;
|
|
||||||
|
|
||||||
{ Now compress the files }
|
|
||||||
FZip := TZipper.Create;
|
|
||||||
try
|
|
||||||
FZip.FileName := '__temp__.tmp';
|
|
||||||
|
|
||||||
FZip.Entries.AddFileEntry(FSMeta, OPENDOC_PATH_META);
|
|
||||||
FZip.Entries.AddFileEntry(FSSettings, OPENDOC_PATH_SETTINGS);
|
|
||||||
FZip.Entries.AddFileEntry(FSStyles, OPENDOC_PATH_STYLES);
|
|
||||||
FZip.Entries.AddFileEntry(FSContent, OPENDOC_PATH_CONTENT);
|
|
||||||
FZip.Entries.AddFileEntry(FSMimetype, OPENDOC_PATH_MIMETYPE);
|
|
||||||
FZip.Entries.AddFileEntry(FSMetaInfManifest, OPENDOC_PATH_METAINF_MANIFEST);
|
|
||||||
|
|
||||||
ResetStreams;
|
|
||||||
|
|
||||||
FZip.SaveToStream(AStream);
|
|
||||||
|
|
||||||
finally
|
|
||||||
DestroyStreams;
|
|
||||||
FZip.Free;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ Writes an empty cell to the stream }
|
{ Writes an empty cell to the stream }
|
||||||
@ -6117,6 +6146,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@ -468,7 +468,7 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Types, Math, StrUtils, TypInfo, LCLType, LCLIntf, LCLProc,
|
Types, Math, StrUtils, TypInfo, LCLType, LCLIntf, LCLProc,
|
||||||
Dialogs, Forms, Clipbrd,
|
Dialogs, Forms, Clipbrd,
|
||||||
fpsStrings, fpsUtils, fpsNumFormat, fpsHTMLUtils, fpsCSV;
|
fpsStrings, fpsUtils, fpsNumFormat, fpsHTMLUtils, fpsCSV, fpsOpenDocument;
|
||||||
|
|
||||||
var
|
var
|
||||||
cfBiff8Format: Integer = 0;
|
cfBiff8Format: Integer = 0;
|
||||||
@ -477,6 +477,7 @@ var
|
|||||||
cfTextHTMLFormat: Integer = 0;
|
cfTextHTMLFormat: Integer = 0;
|
||||||
cfCSVFormat: Integer = 0;
|
cfCSVFormat: Integer = 0;
|
||||||
cfOpenDocumentFormat: Integer = 0;
|
cfOpenDocumentFormat: Integer = 0;
|
||||||
|
cfStarObjectDescriptor: Integer = 0;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Registers the spreadsheet components in the Lazarus component palette,
|
Registers the spreadsheet components in the Lazarus component palette,
|
||||||
@ -1136,7 +1137,17 @@ var
|
|||||||
sel: TsCellRangeArray;
|
sel: TsCellRangeArray;
|
||||||
stream: TStream;
|
stream: TStream;
|
||||||
savedCSVParams: TsCSVParams;
|
savedCSVParams: TsCSVParams;
|
||||||
param: Integer;
|
|
||||||
|
procedure CopyToClipboard(AStream: TStream; AFileFormat: TsSpreadsheetFormat;
|
||||||
|
AClipboardFormat: Integer; AParam: Integer = 0);
|
||||||
|
begin
|
||||||
|
if AClipboardFormat = 0 then
|
||||||
|
exit;
|
||||||
|
FWorkbook.CopyToClipboardStream(AStream, AFileFormat, AParam);
|
||||||
|
Clipboard.AddFormat(AClipboardFormat, AStream);
|
||||||
|
(AStream as TMemoryStream).Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
sel := FWorksheet.GetSelection;
|
sel := FWorksheet.GetSelection;
|
||||||
if Length(sel) = 0 then
|
if Length(sel) = 0 then
|
||||||
@ -1149,82 +1160,47 @@ begin
|
|||||||
stream := TMemoryStream.Create;
|
stream := TMemoryStream.Create;
|
||||||
try
|
try
|
||||||
// Write OpenDocument format
|
// Write OpenDocument format
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfOpenDocument);
|
CopyToClipboard(stream, sfOpenDocument, cfOpenDocumentFormat);
|
||||||
if cfOpenDocumentFormat <> 0 then
|
|
||||||
Clipboard.AddFormat(cfOpenDocumentFormat, stream);
|
// Write OpenDocument's "Star Object Descriptor"
|
||||||
|
WriteStarObjectDescriptorToStream(stream);
|
||||||
|
if cfStarObjectDescriptor <> 0 then
|
||||||
|
Clipboard.AddFormat(cfStarObjectDescriptor, stream);
|
||||||
(stream as TMemoryStream).Clear;
|
(stream as TMemoryStream).Clear;
|
||||||
|
|
||||||
// Write BIFF8 format
|
// Write BIFF8 format
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfExcel8);
|
CopyToClipboard(stream, sfExcel8, cfBiff8Format);
|
||||||
if cfBiff8Format <> 0 then
|
|
||||||
Clipboard.AddFormat(cfBiff8Format, stream);
|
|
||||||
(stream as TMemoryStream).Clear;
|
|
||||||
|
|
||||||
// Then write BIFF5 format
|
// Then write BIFF5 format
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfExcel5);
|
CopyToClipboard(stream, sfExcel5, cfBiff5Format);
|
||||||
if cfBiff5Format <> 0 then
|
|
||||||
Clipboard.AddFormat(cfBiff5Format, stream);
|
|
||||||
(stream as TMemoryStream).Clear;
|
|
||||||
|
|
||||||
// Then write Windows HTML format
|
// Then write Windows HTML format
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
param := PARAM_WINDOWS_CLIPBOARD_HTML;
|
CopyToClipboard(stream, sfHTML, cfHtmlFormat, PARAM_WINDOWS_CLIPBOARD_HTML);
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfHTML, param);
|
|
||||||
if cfHtmlFormat <> 0 then
|
|
||||||
Clipboard.AddFormat(cfHTMLFormat, stream);
|
|
||||||
(stream as TMemoryStream).Clear;
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
// Write standard html format (MIME-type "text/html")
|
// Write standard html format (MIME-type "text/html")
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfHTML);
|
CopyToClipboard(stream, sfHTML, cfTextHTMLFormat);
|
||||||
if cfTextHtmlFormat <> 0 then
|
|
||||||
Clipboard.AddFormat(cfTextHTMLFormat, stream);
|
|
||||||
(stream as TMemoryStream).Clear;
|
|
||||||
|
|
||||||
// Then write CSV format
|
// Then write CSV format
|
||||||
savedCSVParams := CSVParams;
|
savedCSVParams := CSVParams;
|
||||||
CsvParams.Delimiter := ';';
|
CsvParams.Delimiter := ';';
|
||||||
CsvParams.AutoDetectNumberFormat := false;
|
CsvParams.AutoDetectNumberFormat := false;
|
||||||
CsvParams.SheetIndex := FWorkbook.GetWorksheetIndex(FWorkbook.ActiveWorksheet);
|
CsvParams.SheetIndex := FWorkbook.GetWorksheetIndex(FWorkbook.ActiveWorksheet);
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfCSV);
|
CopyToClipboard(stream, sfCSV, cfCSVFormat);
|
||||||
if cfCSVFormat <> 0 then
|
|
||||||
Clipboard.AddFormat(cfCSVFormat, stream);
|
|
||||||
(stream as TMemoryStream).Clear;
|
|
||||||
|
|
||||||
// Finally write TEXT format
|
// Finally write TEXT format
|
||||||
CsvParams.Delimiter := #9;
|
CsvParams.Delimiter := #9;
|
||||||
FWorkbook.CopyToClipboardStream(stream, sfCSV);
|
CopyToClipboard(stream, sfCSV, CF_TEXT);
|
||||||
Clipboard.AddFormat(CF_TEXT, stream);
|
|
||||||
CSVParams := savedCSVParams;
|
CSVParams := savedCSVParams;
|
||||||
(stream as TMemoryStream).Clear;
|
|
||||||
|
|
||||||
// To do: XML format
|
// To do: XML format
|
||||||
// I don't know which format is written by xlsx and ods natively.
|
|
||||||
finally
|
finally
|
||||||
stream.Free;
|
stream.Free;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
Clipboard.Close;
|
Clipboard.Close;
|
||||||
end;
|
end;
|
||||||
(*
|
|
||||||
exit;
|
|
||||||
|
|
||||||
|
|
||||||
ClearCellClipboard;
|
|
||||||
|
|
||||||
for i:=0 to High(sel) do
|
|
||||||
for r := sel[i].Row1 to sel[i].Row2 do
|
|
||||||
for c := sel[i].Col1 to sel[i].Col2 do
|
|
||||||
begin
|
|
||||||
cell := FWorksheet.FindCell(r, c);
|
|
||||||
if cell = nil then
|
|
||||||
CellClipboard.AddEmptyCell(r, c)
|
|
||||||
else
|
|
||||||
CellClipboard.AddCell(cell);
|
|
||||||
end;
|
|
||||||
|
|
||||||
CellClipboard.MultipleRanges := (Length(sel) > 1);
|
|
||||||
*)
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
@ -3200,6 +3176,7 @@ initialization
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
*)
|
*)
|
||||||
cfOpenDocumentFormat := RegisterClipboardFormat('application/x-openoffice-embed-source-xml;windows_formatname="Star Embed Source (XML)"');
|
cfOpenDocumentFormat := RegisterClipboardFormat('application/x-openoffice-embed-source-xml;windows_formatname="Star Embed Source (XML)"');
|
||||||
|
cfStarObjectDescriptor := RegisterClipboardFormat('application/x-openoffice-objectdescriptor-xml;windows_formatname="Star Object Descriptor (XML)"');
|
||||||
// cfOpenDocumentFormat := RegisterClipboardFormat('application/x-openoffice;windows_formatname="Star Embed Source (XML)"');
|
// cfOpenDocumentFormat := RegisterClipboardFormat('application/x-openoffice;windows_formatname="Star Embed Source (XML)"');
|
||||||
//cfOpenDocumentFormat := RegisterClipboardFormat('Star Embed Source (XML)');
|
//cfOpenDocumentFormat := RegisterClipboardFormat('Star Embed Source (XML)');
|
||||||
// cfBiff8Format := RegisterClipboardFormat('application/vnd.ms-excel'); //Biff8');
|
// cfBiff8Format := RegisterClipboardFormat('application/vnd.ms-excel'); //Biff8');
|
||||||
|
Reference in New Issue
Block a user