You've already forked lazarus-ccr
fpspreadsheet: Write custom row heights and column widths to xlsx files. Works in virtual mode also.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3320 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -36,6 +36,9 @@ begin
|
|||||||
|
|
||||||
MyWorksheet.WriteUTF8Text(0, 26, 'AA'); // Test for column name
|
MyWorksheet.WriteUTF8Text(0, 26, 'AA'); // Test for column name
|
||||||
|
|
||||||
|
MyWorksheet.WriteColWidth(0, 20);
|
||||||
|
MyWorksheet.WriteRowHeight(0, 4);
|
||||||
|
|
||||||
// Uncomment this to test large XLS files
|
// Uncomment this to test large XLS files
|
||||||
for i := 2 to 2{20} do
|
for i := 2 to 2{20} do
|
||||||
begin
|
begin
|
||||||
|
@@ -90,6 +90,8 @@ begin
|
|||||||
worksheet.WriteBackgroundColor(0, 0, scSilver);
|
worksheet.WriteBackgroundColor(0, 0, scSilver);
|
||||||
headerTemplate := worksheet.FindCell(0, 0);
|
headerTemplate := worksheet.FindCell(0, 0);
|
||||||
|
|
||||||
|
worksheet.WriteRowHeight(0, 3);
|
||||||
|
worksheet.WriteColWidth(0, 30);
|
||||||
{ In case of a database, you would open the dataset before calling this: }
|
{ In case of a database, you would open the dataset before calling this: }
|
||||||
workbook.WriteToFile('test_virtual.xlsx', sfOOXML, true);
|
workbook.WriteToFile('test_virtual.xlsx', sfOOXML, true);
|
||||||
// workbook.WriteToFile('test_virtual.xls', sfExcel8, true);
|
// workbook.WriteToFile('test_virtual.xls', sfExcel8, true);
|
||||||
|
@@ -19,6 +19,9 @@ Specifications obtained from:
|
|||||||
|
|
||||||
http://openxmldeveloper.org/default.aspx
|
http://openxmldeveloper.org/default.aspx
|
||||||
|
|
||||||
|
also:
|
||||||
|
http://office.microsoft.com/en-us/excel-help/excel-specifications-and-limits-HP010073849.aspx#BMworksheetworkbook
|
||||||
|
|
||||||
AUTHORS: Felipe Monteiro de Carvalho
|
AUTHORS: Felipe Monteiro de Carvalho
|
||||||
}
|
}
|
||||||
unit xlsxooxml;
|
unit xlsxooxml;
|
||||||
@@ -72,6 +75,7 @@ type
|
|||||||
procedure ListAllFills;
|
procedure ListAllFills;
|
||||||
procedure ResetStreams;
|
procedure ResetStreams;
|
||||||
procedure WriteBorderList(AStream: TStream);
|
procedure WriteBorderList(AStream: TStream);
|
||||||
|
procedure WriteCols(AStream: TStream; ASheet: TsWorksheet);
|
||||||
procedure WriteFillList(AStream: TStream);
|
procedure WriteFillList(AStream: TStream);
|
||||||
procedure WriteFontList(AStream: TStream);
|
procedure WriteFontList(AStream: TStream);
|
||||||
procedure WriteNumFormatList(AStream: TStream);
|
procedure WriteNumFormatList(AStream: TStream);
|
||||||
@@ -443,6 +447,30 @@ begin
|
|||||||
'</borders>');
|
'</borders>');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadOOXMLWriter.WriteCols(AStream: TStream; ASheet: TsWorksheet);
|
||||||
|
var
|
||||||
|
col: PCol;
|
||||||
|
c: Integer;
|
||||||
|
begin
|
||||||
|
if ASheet.Cols.Count = 0 then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
AppendToStream(AStream,
|
||||||
|
'<cols>');
|
||||||
|
|
||||||
|
for c:=0 to ASheet.GetLastColIndex do begin
|
||||||
|
col := ASheet.FindCol(c);
|
||||||
|
if col <> nil then
|
||||||
|
AppendToStream(AStream, Format(
|
||||||
|
'<col min="%d" max="%d" width="%g" customWidth="1" />',
|
||||||
|
[c+1, c+1, col.Width])
|
||||||
|
);
|
||||||
|
end;
|
||||||
|
|
||||||
|
AppendToStream(AStream,
|
||||||
|
'</cols>');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOOXMLWriter.WriteFillList(AStream: TStream);
|
procedure TsSpreadOOXMLWriter.WriteFillList(AStream: TStream);
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
@@ -848,9 +876,13 @@ var
|
|||||||
value: Variant;
|
value: Variant;
|
||||||
styleCell: PCell;
|
styleCell: PCell;
|
||||||
fn: String;
|
fn: String;
|
||||||
|
row: PRow;
|
||||||
|
rh: String;
|
||||||
|
h0: Single;
|
||||||
begin
|
begin
|
||||||
FCurSheetNum := Length(FSSheets);
|
FCurSheetNum := Length(FSSheets);
|
||||||
SetLength(FSSheets, FCurSheetNum + 1);
|
SetLength(FSSheets, FCurSheetNum + 1);
|
||||||
|
h0 := Workbook.GetDefaultFontSize; // Point size of default font
|
||||||
|
|
||||||
// Create the stream
|
// Create the stream
|
||||||
if (woSaveMemory in Workbook.WritingOptions) then begin
|
if (woSaveMemory in Workbook.WritingOptions) then begin
|
||||||
@@ -871,14 +903,23 @@ begin
|
|||||||
'<sheetView workbookViewId="0" />');
|
'<sheetView workbookViewId="0" />');
|
||||||
AppendToStream(FSSheets[FCurSheetNum],
|
AppendToStream(FSSheets[FCurSheetNum],
|
||||||
'</sheetViews>');
|
'</sheetViews>');
|
||||||
|
|
||||||
|
WriteCols(FSSheets[FCurSheetNum], CurSheet);
|
||||||
|
|
||||||
AppendToStream(FSSheets[FCurSheetNum],
|
AppendToStream(FSSheets[FCurSheetNum],
|
||||||
'<sheetData>');
|
'<sheetData>');
|
||||||
|
|
||||||
if (woVirtualMode in Workbook.WritingOptions) and Assigned(Workbook.OnNeedCellData)
|
if (woVirtualMode in Workbook.WritingOptions) and Assigned(Workbook.OnNeedCellData)
|
||||||
then begin
|
then begin
|
||||||
for r := 0 to Workbook.VirtualRowCount-1 do begin
|
for r := 0 to Workbook.VirtualRowCount-1 do begin
|
||||||
|
row := CurSheet.FindRow(r);
|
||||||
|
if row <> nil then
|
||||||
|
rh := Format(' ht="%g" customHeight="1"', [
|
||||||
|
(row^.Height + ROW_HEIGHT_CORRECTION)*h0])
|
||||||
|
else
|
||||||
|
rh := '';
|
||||||
AppendToStream(FSSheets[FCurSheetNum], Format(
|
AppendToStream(FSSheets[FCurSheetNum], Format(
|
||||||
'<row r="%d" spans="1:%d">', [r+1, Workbook.VirtualColCount]));
|
'<row r="%d" spans="1:%d"%s>', [r+1, Workbook.VirtualColCount, rh]));
|
||||||
for c := 0 to Workbook.VirtualColCount-1 do begin
|
for c := 0 to Workbook.VirtualColCount-1 do begin
|
||||||
FillChar(lCell, SizeOf(lCell), 0);
|
FillChar(lCell, SizeOf(lCell), 0);
|
||||||
CellPosText := CurSheet.CellPosToText(r, c);
|
CellPosText := CurSheet.CellPosToText(r, c);
|
||||||
@@ -920,8 +961,15 @@ begin
|
|||||||
// The cells need to be written in order, row by row, cell by cell
|
// The cells need to be written in order, row by row, cell by cell
|
||||||
LastColIndex := CurSheet.GetLastColIndex;
|
LastColIndex := CurSheet.GetLastColIndex;
|
||||||
for r := 0 to CurSheet.GetLastRowIndex do begin
|
for r := 0 to CurSheet.GetLastRowIndex do begin
|
||||||
|
// If the row has a custom height add this value to the <row> specification
|
||||||
|
row := CurSheet.FindRow(r);
|
||||||
|
if row <> nil then
|
||||||
|
rh := Format(' ht="%g" customHeight="1"', [
|
||||||
|
(row^.Height + ROW_HEIGHT_CORRECTION)*h0])
|
||||||
|
else
|
||||||
|
rh := '';
|
||||||
AppendToStream(FSSheets[FCurSheetNum], Format(
|
AppendToStream(FSSheets[FCurSheetNum], Format(
|
||||||
'<row r="%d" spans="1:%d">', [r+1, LastColIndex+1]));
|
'<row r="%d" spans="1:%d"%s>', [r+1, LastColIndex+1, rh]));
|
||||||
// Write cells belonging to this row.
|
// Write cells belonging to this row.
|
||||||
for c := 0 to LastColIndex do begin
|
for c := 0 to LastColIndex do begin
|
||||||
LCell.Row := r;
|
LCell.Row := r;
|
||||||
|
Reference in New Issue
Block a user