diff --git a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi
index 607bca344..f3b13bc41 100644
--- a/components/fpspreadsheet/examples/excel2demo/excel2read.lpi
+++ b/components/fpspreadsheet/examples/excel2demo/excel2read.lpi
@@ -10,7 +10,7 @@
-
+
@@ -26,7 +26,7 @@
-
+
@@ -39,8 +39,8 @@
-
-
+
+
@@ -69,7 +69,7 @@
-
+
diff --git a/components/fpspreadsheet/examples/excel2demo/excel2read.lpr b/components/fpspreadsheet/examples/excel2demo/excel2read.lpr
index 21f3f6d5e..22d579dce 100644
--- a/components/fpspreadsheet/examples/excel2demo/excel2read.lpr
+++ b/components/fpspreadsheet/examples/excel2demo/excel2read.lpr
@@ -40,7 +40,8 @@ begin
begin
CurCell := MyWorkSheet.GetCellByIndex(i);
WriteLn('Row: ', CurCell^.Row, ' Col: ', CurCell^.Col, ' Value: ',
- MyWorkSheet.ReadAsAnsiText(CurCell^.Row, CurCell^.Col));
+ UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row, CurCell^.Col))
+ );
end;
// Finalization
diff --git a/components/fpspreadsheet/examples/excel2demo/excel2write.lpi b/components/fpspreadsheet/examples/excel2demo/excel2write.lpi
index 144c4522b..52bac16cb 100644
--- a/components/fpspreadsheet/examples/excel2demo/excel2write.lpi
+++ b/components/fpspreadsheet/examples/excel2demo/excel2write.lpi
@@ -26,7 +26,7 @@
-
+
@@ -39,8 +39,8 @@
-
-
+
+
@@ -130,7 +130,7 @@
-
+
@@ -235,6 +235,10 @@
+
+
+
+
diff --git a/components/fpspreadsheet/examples/excel2demo/excel2write.lpr b/components/fpspreadsheet/examples/excel2demo/excel2write.lpr
index fe38d3024..931e786b3 100644
--- a/components/fpspreadsheet/examples/excel2demo/excel2write.lpr
+++ b/components/fpspreadsheet/examples/excel2demo/excel2write.lpr
@@ -31,10 +31,10 @@ begin
MyWorksheet.WriteNumber(0, 3, 4.0);
// Write some string cells
- MyWorksheet.WriteAnsiText(1, 0, 'First');
- MyWorksheet.WriteAnsiText(1, 1, 'Second');
- MyWorksheet.WriteAnsiText(1, 2, 'Third');
- MyWorksheet.WriteAnsiText(1, 3, 'Fourth');
+ MyWorksheet.WriteUTF8Text(1, 0, 'First');
+ MyWorksheet.WriteUTF8Text(1, 1, 'Second');
+ MyWorksheet.WriteUTF8Text(1, 2, 'Third');
+ MyWorksheet.WriteUTF8Text(1, 3, 'Fourth');
// Save the spreadsheet to a file
MyWorkbook.WriteToFile(MyDir + 'test' + STR_EXCEL_EXTENSION, sfExcel2);
diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi
index fad98ee92..511f850a4 100644
--- a/components/fpspreadsheet/examples/excel5demo/excel5read.lpi
+++ b/components/fpspreadsheet/examples/excel5demo/excel5read.lpi
@@ -10,7 +10,7 @@
-
+
@@ -26,7 +26,7 @@
-
+
@@ -39,7 +39,7 @@
-
+
@@ -69,7 +69,7 @@
-
+
@@ -97,7 +97,7 @@
-
+
@@ -150,7 +150,7 @@
-
+
@@ -205,72 +205,68 @@
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
+
+
+
+
-
+
-
+
-
-
-
-
-
+
diff --git a/components/fpspreadsheet/examples/excel5demo/excel5read.lpr b/components/fpspreadsheet/examples/excel5demo/excel5read.lpr
index c4625a342..aa566dfa4 100644
--- a/components/fpspreadsheet/examples/excel5demo/excel5read.lpr
+++ b/components/fpspreadsheet/examples/excel5demo/excel5read.lpr
@@ -40,7 +40,8 @@ begin
begin
CurCell := MyWorkSheet.GetCellByIndex(i);
WriteLn('Row: ', CurCell^.Row, ' Col: ', CurCell^.Col, ' Value: ',
- MyWorkSheet.ReadAsAnsiText(CurCell^.Row, CurCell^.Col));
+ UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(CurCell^.Row, CurCell^.Col))
+ );
end;
// Finalization
diff --git a/components/fpspreadsheet/examples/excel5demo/excel5write.lpi b/components/fpspreadsheet/examples/excel5demo/excel5write.lpi
index ab6d801d0..a6b230e4f 100644
--- a/components/fpspreadsheet/examples/excel5demo/excel5write.lpi
+++ b/components/fpspreadsheet/examples/excel5demo/excel5write.lpi
@@ -26,7 +26,7 @@
-
+
@@ -40,7 +40,7 @@
-
+
diff --git a/components/fpspreadsheet/examples/excel5demo/excel5write.lpr b/components/fpspreadsheet/examples/excel5demo/excel5write.lpr
index 036ae493d..accb4d33f 100644
--- a/components/fpspreadsheet/examples/excel5demo/excel5write.lpr
+++ b/components/fpspreadsheet/examples/excel5demo/excel5write.lpr
@@ -59,10 +59,10 @@ begin
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
// Write some string cells
- MyWorksheet.WriteAnsiText(0, 0, 'First');
- MyWorksheet.WriteAnsiText(0, 1, 'Second');
- MyWorksheet.WriteAnsiText(0, 2, 'Third');
- MyWorksheet.WriteAnsiText(0, 3, 'Fourth');
+ MyWorksheet.WriteUTF8Text(0, 0, 'First');
+ MyWorksheet.WriteUTF8Text(0, 1, 'Second');
+ MyWorksheet.WriteUTF8Text(0, 2, 'Third');
+ MyWorksheet.WriteUTF8Text(0, 3, 'Fourth');
// Save the spreadsheet to a file
MyWorkbook.WriteToFile(MyDir + 'test' + STR_EXCEL_EXTENSION, sfExcel5);
diff --git a/components/fpspreadsheet/fpspreadsheet.pas b/components/fpspreadsheet/fpspreadsheet.pas
index e29ed1f6b..579c51c07 100755
--- a/components/fpspreadsheet/fpspreadsheet.pas
+++ b/components/fpspreadsheet/fpspreadsheet.pas
@@ -23,6 +23,8 @@ type
const
{ Default extensions }
STR_EXCEL_EXTENSION = '.xls';
+ STR_OOXML_EXCEL_EXTENSION = '.xlsx';
+ STR_OPENDOCUMENT_CALC_EXTENSION = '.ods';
const
{ TokenID values }
@@ -59,7 +61,7 @@ type
{@@ Describes the type of content of a cell on a TsWorksheet }
- TCellContentType = (cctFormula, cctNumber, cctString, cctWideString);
+ TCellContentType = (cctFormula, cctNumber, cctUTF8String);
{@@ Cell structure for TsWorksheet }
@@ -68,8 +70,7 @@ type
ContentType: TCellContentType;
FormulaValue: TRPNFormula;
NumberValue: double;
- StringValue: string;
- WideStringValue: widestring;
+ UTF8StringValue: ansistring;
end;
PCell = ^TCell;
@@ -97,9 +98,9 @@ type
function GetCell(ARow, ACol: Cardinal): PCell;
function GetCellCount: Cardinal;
function GetCellByIndex(AIndex: Cardinal): PCell;
- function ReadAsAnsiText(ARow, ACol: Cardinal): ansistring;
+ function ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring;
procedure RemoveAllCells;
- procedure WriteAnsiText(ARow, ACol: Cardinal; AText: ansistring);
+ procedure WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring);
procedure WriteNumber(ARow, ACol: Cardinal; ANumber: double);
procedure WriteRPNFormula(ARow, ACol: Cardinal; AFormula: TRPNFormula);
end;
@@ -352,15 +353,17 @@ begin
end;
{@@
- Reads the contents of a cell and converts it to a user readable text,
- if it isn't already a text.
+ Reads the contents of a cell and returns an user readable text
+ representing the contents of the cell.
+
+ The resulting ansistring is UTF-8 encoded.
@param ARow The row of the cell
@param ACol The column of the cell
@return The text representation of the cell
}
-function TsWorksheet.ReadAsAnsiText(ARow, ACol: Cardinal): ansistring;
+function TsWorksheet.ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring;
var
ACell: PCell;
begin
@@ -376,10 +379,9 @@ begin
//cctFormula
cctNumber: Result := FloatToStr(ACell^.NumberValue);
- cctString: Result := ACell^.StringValue;
- cctWideString: Result := ACell^.WideStringValue;
+ cctUTF8String: Result := UTF8ToAnsi(ACell^.UTF8StringValue);
else
- Result := ACell^.StringValue;
+ Result := '';
end;
end;
@@ -392,25 +394,23 @@ begin
end;
{@@
- Writes ansi text to a determined cell.
-
- The text must be encoded on the system default encoding.
-
- On formats the support unicode the text will be converted to the unicode
- encoding that the format supports.
+ Writes UTF-8 encoded text to a determined cell.
+
+ On formats that only support unicode the text will be converted
+ to the unicode encoding that the format supports.
@param ARow The row of the cell
@param ACol The column of the cell
@param AText The text to be written encoded with the system encoding
}
-procedure TsWorksheet.WriteAnsiText(ARow, ACol: Cardinal; AText: ansistring);
+procedure TsWorksheet.WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring);
var
ACell: PCell;
begin
ACell := GetCell(ARow, ACol);
- ACell^.ContentType := cctString;
- ACell^.StringValue := AText;
+ ACell^.ContentType := cctUTF8String;
+ ACell^.UTF8StringValue := AText;
end;
{@@
@@ -714,7 +714,7 @@ begin
case ACell.ContentType of
cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue);
cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue);
- cctString: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.StringValue);
+ cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue);
end;
end;
diff --git a/components/fpspreadsheet/xlsbiff2.pas b/components/fpspreadsheet/xlsbiff2.pas
index bfc2a0b31..28c4eb4b6 100755
--- a/components/fpspreadsheet/xlsbiff2.pas
+++ b/components/fpspreadsheet/xlsbiff2.pas
@@ -240,8 +240,10 @@ procedure TsSpreadBIFF2Writer.WriteLabel(AStream: TStream; const ARow,
ACol: Word; const AValue: string);
var
L: Byte;
+ AnsiText: ansistring;
begin
- L := Length(AValue);
+ AnsiText := UTF8ToAnsi(AValue);
+ L := Length(AnsiText);
{ BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_LABEL));
@@ -258,7 +260,7 @@ begin
{ String with 8-bit size }
AStream.WriteByte(L);
- AStream.WriteBuffer(AValue[1], L);
+ AStream.WriteBuffer(AnsiText[1], L);
end;
{*******************************************************************
@@ -357,7 +359,7 @@ begin
AStrValue := AValue;
{ Save the data }
- FWorksheet.WriteAnsiText(ARow, ACol, AStrValue);
+ FWorksheet.WriteUTF8Text(ARow, ACol, AnsiToUTF8(AStrValue));
end;
procedure TsSpreadBIFF2Reader.ReadNumber(AStream: TStream);
diff --git a/components/fpspreadsheet/xlsbiff5.pas b/components/fpspreadsheet/xlsbiff5.pas
index cf8b7d196..8e7c330bd 100755
--- a/components/fpspreadsheet/xlsbiff5.pas
+++ b/components/fpspreadsheet/xlsbiff5.pas
@@ -657,8 +657,10 @@ procedure TsSpreadBIFF5Writer.WriteLabel(AStream: TStream; const ARow,
ACol: Word; const AValue: string);
var
L: Word;
+ AnsiValue: ansistring;
begin
- L := Length(AValue);
+ AnsiValue := UTF8ToAnsi(AValue);
+ L := Length(AnsiValue);
{ BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_LABEL));
@@ -673,7 +675,7 @@ begin
{ Byte String with 16-bit size }
AStream.WriteWord(L);
- AStream.WriteBuffer(AValue[1], L);
+ AStream.WriteBuffer(AnsiValue[1], L);
end;
{*******************************************************************