{*******************************************************************}
{ }
{ Developer Express Cross Platform Component Library }
{ ExpressExport }
{ }
{ Copyright (c) 2001-2009 Developer Express Inc. }
{ ALL RIGHTS RESERVED }
{ }
{ The entire contents of this file is protected by U.S. and }
{ International Copyright Laws. Unauthorized reproduction, }
{ reverse-engineering, and distribution of all or any portion of }
{ the code contained in this file is strictly prohibited and may }
{ result in severe civil and criminal penalties and will be }
{ prosecuted to the maximum extent possible under the law. }
{ }
{ RESTRICTIONS }
{ }
{ THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
{ (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE }
{ SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
{ LICENSED TO DISTRIBUTE THE EXPRESSEXPORT AND ALL }
{ ACCOMPANYING VCL AND CLX CONTROLS AS PART OF AN EXECUTABLE }
{ PROGRAM ONLY. }
{ }
{ THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
{ FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
{ COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
{ AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
{ AND PERMISSION FROM DEVELOPER EXPRESS INC. }
{ }
{ CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
{ ADDITIONAL RESTRICTIONS. }
{ }
{*******************************************************************}
unit cxHtmlXmlTxtExport;
{$I cxVer.inc}
interface
uses
SysUtils, Math, Classes,
Windows,
{$IFDEF DELPHI6} Variants, {$IFNDEF NONDB} FMTBcd, SqlTimSt, {$ENDIF} {$ENDIF}
cxExport, cxExportStrs, Graphics;
const
CharsetTag: string = {$IFDEF DELPHI12}' charset=utf-8' {$ELSE} '' {$ENDIF};
EncodingTag: string = '';
type
{ TcxCustomHtmlXmlTXTExportProvider }
TcxCustomHtmlXmlTXTExportProvider = class(TcxCustomExportProvider, IcxExportProvider)
private
FCache: array of array of TcxCacheItem;
FColumns: array of Integer;
FDefaultStyle: TcxCacheCellStyle;
FInternalCacheList: TInterfaceList;
FName: string;
FRows: array of Integer;
FStyleManager: TcxExportStyleManager;
function GetCacheItem(ACol, ARow: Integer): TcxCacheItem;
function GetCellHeight(ACol, ARow: Integer): Integer;
function GetCellWidth(ACol, ARow: Integer): Integer;
function GetColumns(ACol: Integer): Integer;
function GetDefaultStyle: PcxCacheCellStyle;
function GetHeight: Integer;
function GetInternalCacheCount: Integer;
function GetInternalCacheItems(AIndex: Integer): IcxCellInternalCache;
function GetRows(ARow: Integer): Integer;
function GetStyleCount: Integer;
function GetWidth: Integer;
procedure TestIndex(ACol, ARow: Integer);
procedure TestCol(ACol: Integer);
procedure TestRow(ARow: Integer);
procedure TestStyleIndex(AStyleIndex: Integer);
protected
procedure Clear; override;
function GetCellData(const ACol, ARow: Integer; var AData): Boolean;
procedure SetData(const ACol, ARow, ADataSize, ADataType: Integer; const AData);
procedure SetEmptyData(const ACol, ARow, ADataType: Integer);
procedure Commit; dynamic;
function GetCacheName: string;
function GetCellStyle(const ACol, ARow: Integer): PcxCacheCellStyle;
function GetExportType: Integer;
function GetExportName: string;
function GetStyle(AStyleIndex: Integer): PcxCacheCellStyle;
function RegisterStyle(const AStyle: TcxCacheCellStyle): Integer;
procedure SetCellDataString(const ACol, ARow: Integer; const AText: string); virtual;
procedure SetCellDataAnsiString(const ACol, ARow: Integer; const AText: AnsiString); virtual;
procedure SetCellDataWideString(const ACol, ARow: Integer; const AText: WideString); virtual;
procedure SetCellDataDouble(const ACol, ARow: Integer; const AValue: Double); virtual;
procedure SetCellDataInteger(const ACol, ARow: Integer; const AValue: Integer); virtual;
procedure SetCellStyle(const ACol, ARow, AStyleIndex: Integer); overload; virtual;
procedure SetCellStyle(const ACol, ARow, AExampleCol, AExampleRow: Integer); overload; virtual;
procedure SetCellStyle(const ACol, ARow: Integer; const AStyle: TcxCacheCellStyle); overload; virtual;
procedure SetCellStyleEx(const ACol, ARow, H, W: Integer; const AStyleIndex: Integer);
procedure SetCellUnion(const ACol, ARow: Integer; H, W: Integer);
procedure SetCellValue(const ACol, ARow: Integer; const AValue: Variant);
procedure SetColumnWidth(const ACol, AWidth: Integer);
procedure SetDefaultStyle(const AStyle: TcxCacheCellStyle);
procedure SetRange(const AColCount, ARowCount: Integer; IsVisible: Boolean = True);
procedure SetRowHeight(const ARow, AHeight: Integer);
// export graphic extension
procedure SetCellDataGraphic(const ACol, ARow: Integer; var AGraphic: TGraphic);
function SupportGraphic: Boolean; virtual;
property Cache[ACol, ARow: Integer]: TcxCacheItem read GetCacheItem;
property Columns[ACol: Integer]: Integer read GetColumns;
property DefaultStyle: PcxCacheCellStyle read GetDefaultStyle;
property RowCount: Integer read GetHeight;
property InternalCacheCount: Integer read GetInternalCacheCount;
property InternalCacheItems[AIndex: Integer]: IcxCellInternalCache read GetInternalCacheItems;
property Name: string read FName write FName;
property Rows[ARow: Integer]: Integer read GetRows;
property StyleCount: Integer read GetStyleCount;
property Styles[AIndex: Integer]: PcxCacheCellStyle read GetStyle;
property CellHeight[ACol, ARow: Integer]: Integer read GetCellHeight;
property CellWidth[ACol, ARow: Integer]: Integer read GetCellWidth;
property ColCount: Integer read GetWidth;
public
constructor Create(const AFileName: string); override;
destructor Destroy; override;
end;
{ TcxCustomExportProviderSupportedCellInternalChache }
TcxCustomExportProviderSupportedCellInternalChache = class(TcxCustomHtmlXmlTXTExportProvider, IcxCellInternalCache)
protected
procedure CommitCache(AStream: TStream; AParam: Pointer); virtual;
procedure CommitStyle(AStream: TStream; AParam: Pointer); virtual;
procedure DeleteCacheFromCell(const ACol, ARow: Integer);
procedure SetCacheIntoCell(const ACol, ARow: Integer; ACache: IcxCellInternalCache);
procedure SetEmptyCellsStyle;
end;
{ TcxHTMLExportProvider }
TcxHTMLExportProvider = class(TcxCustomExportProviderSupportedCellInternalChache)
private
procedure CommitHTML(AStream: TStream);
function GetStyle(AStyle: TcxCacheCellStyle): string;
function GetScaleRow: string;
protected
procedure CommitCache(AStream: TStream; AParam: Pointer); override;
procedure CommitStyle(AStream: TStream; AParam: Pointer); override;
function GetContentWidth: Integer;
public
procedure Commit; override;
class function ExportType: Integer; override;
class function ExportName: string; override;
end;
{ TcxXMLExportProvider }
TcxXMLExportProvider = class(TcxCustomExportProviderSupportedCellInternalChache)
private
FHideDotsOn: Boolean;
FXSLFileName: WideString;
procedure CommitXML(AStream: TStream);
procedure CommitXSL(AStream: TStream);
function ConvertTextToXML(const AText: string; ACol, ARow: Integer): string;
function GetBorderStyle(AStyle: TcxCacheCellStyle): string;
function GetCellParams(ACol, ARow: Integer): string;
function GetData(ACol, ARow: Integer): string;
function GetStyle(AStyle: TcxCacheCellStyle): string;
procedure HideDots;
function GetScaleLine: string;
protected
procedure CommitCache(AStream: TStream; AParam: Pointer); override;
procedure CommitStyle(AStream: TStream; AParam: Pointer); override;
public
constructor Create(const AFileName: string); override;
procedure Commit; override;
class function ExportType: Integer; override;
class function ExportName: string; override;
end;
{ TcxTXTExportProvider }
TcxTXTExportProvider = class(TcxCustomExportProviderSupportedCellInternalChache, IcxExportWithSeparators)
private
FBeginString: string;
FColMaxWidth: array of Integer;
FEndString: string;
FIndex: Integer;
FSeparator: string;
procedure CalculateColMaxWidth;
function GetData(ACol, ARow: Integer): string;
protected
procedure AddSeparator(const ASeparator: string);
procedure CommitCache(AStream: TStream; AParam: Pointer); override;
function SupportGraphic: Boolean; override;
public
constructor Create(const AFileName: string); override;
procedure Commit; override;
class function ExportType: Integer; override;
class function ExportName: string; override;
end;
const
cxXMLEmptyChar = '.';
cxExportDefaultEmptyString: string = ' ';
implementation
uses
dxCore;
function HasBorders(ACellStyle: PcxCacheCellStyle): Boolean;
var
I: Integer;
begin
Result := False;
for I := 0 to 3 do
Result := Result or (ACellStyle.Borders[I].Width > 0);
end;
function DirExist(const ADirectory: string): Boolean;
{$IFNDEF DELPHI6}
var
ACode: Integer;
{$ENDIF}
begin
{$IFDEF DELPHI6}
Result := DirectoryExists(ADirectory);
{$ELSE}
ACode := GetFileAttributes(PChar(ADirectory));
Result := (ACode <> -1) and (FILE_ATTRIBUTE_DIRECTORY and ACode <> 0);
{$ENDIF}
end;
function GraphicNeeded(const ADir, AGraphicData: AnsiString; AddTags: Boolean = True): string;
var
F: File;
AGraphicStream: AnsiString;
begin
GetTextAsGraphicStream(AGraphicData, Result, AGraphicStream);
if not DirExist(ExtractFileDir(Result)) then
CreateDir(ExtractFileDir(Result));
AssignFile(F, Result);
Rewrite(F, 1);
try
BlockWrite(F, AGraphicStream[1], Length(AGraphicStream));
finally
CloseFile(F);
end;
Delete(Result, 1, Length(ADir));
while Pos('\', Result) <> 0 do
Result[Pos('\', Result)] := '/';
if AddTags then
Result := '';
end;
function GetHTMLColor(AColor: Integer): string;
begin
Result := Format('rgb(%d,%d,%d)', [GetRValue(AColor), GetGValue(AColor), GetBValue(AColor)]);
end;
function ConvertCRLFSymbols(const AString: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(AString) do
begin
if AString[I] = #13 then
begin
if I < Length(AString) then
if AString[I + 1] = #10 then
begin
Result := Result + '
';
Continue;
end;
end
else if AString[I] = #10 then
begin
if I > 1 then
begin
if AString[I - 1] <> #13 then
Result := Result + '
';
end
else
Result := Result + '
';
Continue;
end;
Result := Result + AString[I];
end;
end;
function ConvertSpecialCharacters(const AString: string): string;
var
I: Integer;
begin
Result := '';
for I := 1 to Length(AString) do
begin
if AString[I] = '<' then
Result := Result + '<'
else if AString[I] = '>' then
Result := Result + '>'
else if AString[I] = '&' then
Result := Result + '&'
else if AString[I] = '"' then
Result := Result + '"'
else
Result := Result + AString[I];
end;
end;
function CheckedUnicodeString(const S: string; ACharset: Integer = 0): string;
var
I: Integer;
W: WideString;
begin
if cxStrUnicodeNeeded(S, True) then
begin
W := cxStrToUnicode(S, ACharset);
Result := '';
for I := 1 to Length(W) do
Result := Result + '' + IntToStr(Integer(W[I])) + ';';
end
else
Result := S;
end;
function CheckedUnicodeStringW(const S: WideString): string;
var
I: Integer;
begin
if cxUnicodeSupported then
begin
Result := '';
for I := 1 to Length(S) do
Result := Result + '' + IntToStr(Integer(S[I])) + ';';
end
else
Result := cxUnicodeToStr(S);
end;
{ TcxCustomHtmlXmlTXTExportProvider }
constructor TcxCustomHtmlXmlTXTExportProvider.Create(const AFileName: string);
begin
inherited Create(AFileName);
FDefaultStyle := DefaultCellStyle;
FInternalCacheList := TInterfaceList.Create;
FStyleManager := TcxExportStyleManager.GetInstance(AFileName);
FName := '';
UseGraphicImages(True);
end;
destructor TcxCustomHtmlXmlTXTExportProvider.Destroy;
begin
UseGraphicImages(False);
FInternalCacheList.Free;
FStyleManager.Clear;
inherited Destroy;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.Clear;
var
I, J: Integer;
begin
for I := 0 to Length(FCache) - 1 do
for J := 0 to Length(FCache[I]) - 1 do
try
with FCache[I, J] do
ReallocMem(FCache[I, J].Data, 0);
finally
FCache[I, J].Data := nil;
FCache[I, J].InternalCache.Cache := nil;
FCache[I, J].InternalCache.Index := -1;
end;
FInternalCacheList.Clear;
SetLength(FCache, 0, 0);
SetLength(FColumns, 0);
SetLength(FRows, 0);
end;
function TcxCustomHtmlXmlTXTExportProvider.GetCacheName: string;
begin
Result := FName;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetCellData(const ACol, ARow: Integer; var AData): Boolean;
begin
TestIndex(ACol, ARow);
with FCache[ACol, ARow] do
begin
Result := Data <> nil;
if Result then
Move(Data^, AData, DataSize);
end;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetCellStyle(const ACol,
ARow: Integer): PcxCacheCellStyle;
begin
TestIndex(ACol, ARow);
with FCache[ACol, ARow] do
begin
if StyleIndex < 0 then
Result := @FDefaultStyle
else
Result := FStyleManager.GetStyle(StyleIndex);
end;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetExportType: Integer;
begin
Result := ExportType;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetExportName: string;
begin
Result := ExportName;
end;
function TcxCustomHtmlXmlTXTExportProvider.RegisterStyle(const AStyle: TcxCacheCellStyle): Integer;
begin
Result := FStyleManager.RegisterStyle(AStyle)
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellDataString(const ACol, ARow: Integer; const AText: string);
const
ADataTypeMap: array[Boolean] of Integer = (cxDataTypeString, cxDataTypeWideString);
var
ADataType: Integer;
begin
ADataType := ADataTypeMap[SizeOf(Char) > 1];
if AText <> '' then
SetData(ACol, ARow, dxStringSize(AText), ADataType, AText[1])
else
SetEmptyData(ACol, ARow, ADataType);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellDataAnsiString(const ACol, ARow: Integer; const AText: AnsiString);
begin
if AText <> '' then
SetData(ACol, ARow, Length(AText), cxDataTypeString, AText[1])
else
SetEmptyData(ACol, ARow, cxDataTypeString);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellDataWideString(const ACol, ARow: Integer; const AText: WideString);
begin
if AText <> '' then
SetData(ACol, ARow, Length(AText) * SizeOf(Char), cxDataTypeWideString, AText[1])
else
SetEmptyData(ACol, ARow, cxDataTypeWideString);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellDataDouble(const ACol, ARow: Integer; const AValue: Double);
begin
SetData(ACol, ARow, Sizeof(Double), cxDataTypeDouble, AValue);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellDataInteger(const ACol, ARow: Integer; const AValue: Integer);
begin
SetData(ACol, ARow, Sizeof(Integer), cxDataTypeInteger, AValue);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellStyle(const ACol, ARow, AStyleIndex: Integer);
begin
TestIndex(ACol, ARow);
TestStyleIndex(AStyleIndex);
FCache[ACol, ARow].StyleIndex := AStyleIndex;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellStyle(const ACol, ARow, AExampleCol,
AExampleRow: Integer);
begin
TestIndex(ACol, ARow);
TestIndex(AExampleCol, AExampleRow);
FCache[ACol, ARow].StyleIndex := FCache[AExampleCol, AExampleRow].StyleIndex;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellStyle(const ACol, ARow: Integer;
const AStyle: TcxCacheCellStyle);
begin
TestIndex(ACol, ARow);
FCache[ACol, ARow].StyleIndex := RegisterStyle(AStyle);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellStyleEx(
const ACol, ARow, H, W: Integer; const AStyleIndex: Integer);
begin
SetCellStyle(ACol, ARow, AStyleIndex);
SetCellUnion(ACol, ARow, H, W);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellUnion(const ACol, ARow: Integer;
H, W: Integer);
var
I, J: Integer;
begin
TestIndex(ACol, ARow);
W := Min(W, Length(FCache) - ACol);
if W < 1 then
W := 1;
H := Min(H, Length(FCache[ACol]) - ARow);
if H < 1 then
H := 1;
with FCache[ACol, ARow] do
begin
IsUnion := True;
Height := H;
Width := W;
for I := ACol to ACol + Width - 1 do
for J := ARow to ARow + Height - 1 do
FCache[I, J].IsHidden := not ((I = ACol) and (J = ARow));
end;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellValue(const ACol,
ARow: Integer; const AValue: Variant);
var
{$IFDEF DELPHI6}
{$IFNDEF NONDB}
ACurr: Currency;
{$ENDIF}
{$ENDIF}
AText: string;
begin
if VarIsNull(AValue) then
AText := ''
else
if TVarData(AValue).VType = varCurrency then
AText := FormatFloat(cxExportCurrencyFormat, Currency(AValue))
else
{$IFDEF DELPHI6}
{$IFNDEF NONDB}
if TVarData(AValue).VType = VarSQLTimeStamp then
AText := DateTimeToStr(AValue)
else
if TVarData(AValue).VType = VarFMTBcd then
begin
if BcdToCurr(VarToBcd(AValue), ACurr) then
AText := FormatFloat(cxExportCurrencyFormat, ACurr)
else
AText := FloatToStr(Double(BcdToDouble(VarToBcd(AValue))));
end
else
{$ENDIF}
{$ENDIF}
AText := AValue;
SetCellDataString(ACol, ARow, AText);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetColumnWidth(const ACol, AWidth: Integer);
begin
TestCol(ACol);
if AWidth < 0 then
raise EcxExportData.Create(cxGetResString(@scxIllegalWidth));
FColumns[ACol] := Abs(AWidth);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetDefaultStyle(const AStyle: TcxCacheCellStyle);
begin
FDefaultStyle := AStyle;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetData(const ACol, ARow, ADataSize,
ADataType: Integer; const AData);
begin
TestIndex(ACol, ARow);
with FCache[ACol, ARow] do
begin
ReallocMem(Data, ADataSize);
Move(AData, Data^, ADataSize);
DataSize := ADataSize;
DataType := ADataType;
end;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetEmptyData(const ACol, ARow, ADataType: Integer);
begin
TestIndex(ACol, ARow);
with FCache[ACol, ARow] do
begin
ReallocMem(Data, 0);
Data := nil;
DataSize := 0;
DataType := ADataType;
end;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.Commit;
begin
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetRange(const AColCount, ARowCount: Integer;
IsVisible: Boolean);
var
I, J, K: Integer;
ABorderWidth: Integer;
begin
if (AColCount <= 0) or (ARowCount <= 0) then
raise EcxExportData.Create(cxGetResString(@scxInvalidColumnRowCount));
SetLength(FCache, AColCount, ARowCount);
SetLength(FColumns, AColCount);
SetLength(FRows, ARowCount);
for I := 0 to ColCount - 1 do
begin
FColumns[I] := 0;
for J := 0 to RowCount - 1 do
begin
with FCache[I, J] do
begin
IsHidden := False;
IsUnion := False;
Height := 1;
Width := 1;
Data := nil;
InternalCache.Cache := nil;
InternalCache.Index := -1;
SetCellStyle(I, J, -1);
end;
end;
end;
if IsVisible then
ABorderWidth := 1
else
ABorderWidth := 0;
for K := 0 to 3 do
FDefaultStyle.Borders[K].Width := ABorderWidth;
for I := 0 to RowCount - 1 do
FRows[I] := 0;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetRowHeight(const ARow, AHeight: Integer);
begin
TestRow(ARow);
if AHeight < 0 then
raise EcxExportData.Create(cxGetResString(@scxIllegalHeight));
FRows[ARow] := AHeight;
end;
procedure TcxCustomHtmlXmlTXTExportProvider.SetCellDataGraphic(
const ACol, ARow: Integer; var AGraphic: TGraphic);
var
AGraphicText: AnsiString;
begin
GetGraphicAsText(cxUnicodeToStr(FileName), AGraphic, AGraphicText);
SetData(ACol, ARow, Length(AGraphicText), cxDataTypeGraphic, AGraphicText[1]);
end;
function TcxCustomHtmlXmlTXTExportProvider.SupportGraphic: Boolean;
begin
Result := True;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetCacheItem(ACol, ARow: Integer): TcxCacheItem;
begin
TestIndex(ACol, ARow);
Result := FCache[ACol, ARow];
end;
function TcxCustomHtmlXmlTXTExportProvider.GetCellHeight(ACol, ARow: Integer): Integer;
var
I: Integer;
begin
TestIndex(ACol, ARow);
if FCache[ACol, ARow].IsUnion then
begin
Result := 0;
for I := 0 to FCache[ACol, ARow].Height - 1 do
Inc(Result, Rows[ARow + I]);
end
else
Result := Rows[ARow];
end;
function TcxCustomHtmlXmlTXTExportProvider.GetCellWidth(ACol, ARow: Integer): Integer;
var
I: Integer;
begin
TestIndex(ACol, ARow);
if FCache[ACol, ARow].IsUnion then
begin
Result := 0;
for I := 0 to FCache[ACol, ARow].Width - 1 do
Inc(Result, Columns[ACol + I]);
end
else
Result := Columns[ACol];
end;
function TcxCustomHtmlXmlTXTExportProvider.GetColumns(ACol: Integer): Integer;
begin
TestCol(ACol);
Result := FColumns[ACol];
end;
function TcxCustomHtmlXmlTXTExportProvider.GetDefaultStyle: PcxCacheCellStyle;
begin
Result := @FDefaultStyle;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetHeight: Integer;
begin
Result := Length(FRows);
end;
function TcxCustomHtmlXmlTXTExportProvider.GetInternalCacheCount: Integer;
begin
Result := FInternalCacheList.Count;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetInternalCacheItems(
AIndex: Integer): IcxCellInternalCache;
begin
Result := FInternalCacheList[AIndex] as IcxCellInternalCache;
end;
function TcxCustomHtmlXmlTXTExportProvider.GetRows(ARow: Integer): Integer;
begin
TestRow(ARow);
Result := FRows[ARow];
end;
function TcxCustomHtmlXmlTXTExportProvider.GetStyle(AStyleIndex: Integer): PcxCacheCellStyle;
begin
TestStyleIndex(AStyleIndex);
if AStyleIndex < 0 then
Result := @FDefaultStyle
else
Result := FStyleManager.GetStyle(AStyleIndex);
end;
function TcxCustomHtmlXmlTXTExportProvider.GetWidth: Integer;
begin
Result := Length(FColumns);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.TestIndex(ACol, ARow: Integer);
begin
TestCol(ACol);
TestRow(ARow);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.TestCol(ACol: Integer);
begin
if (ACol < 0) or (ACol >= Length(FCache)) then
raise EcxExportData.CreateFmt(cxGetResString(@scxInvalidColumnIndex), [ACol]);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.TestRow(ARow: Integer);
begin
if (ARow < 0) or (ARow >= Length(FCache[0])) then
raise EcxExportData.CreateFmt(cxGetResString(@scxInvalidRowIndex), [ARow]);
end;
procedure TcxCustomHtmlXmlTXTExportProvider.TestStyleIndex(AStyleIndex: Integer);
begin
if AStyleIndex >= FStyleManager.Count then
raise EcxExportData.CreateFmt(cxGetResString(@scxInvalidStyleIndex), [AStyleIndex]);
end;
function TcxCustomHtmlXmlTXTExportProvider.GetStyleCount: Integer;
begin
Result := FStyleManager.Count;
end;
{ TcxCustomExportProviderSupportedCellInternalChache }
procedure TcxCustomExportProviderSupportedCellInternalChache.CommitCache(
AStream: TStream; AParam: Pointer);
begin
SetEmptyCellsStyle;
end;
procedure TcxCustomExportProviderSupportedCellInternalChache.CommitStyle(
AStream: TStream; AParam: Pointer);
begin
end;
procedure TcxCustomExportProviderSupportedCellInternalChache.DeleteCacheFromCell(
const ACol, ARow: Integer);
begin
SetCacheIntoCell(ACol, ARow, nil);
end;
procedure TcxCustomExportProviderSupportedCellInternalChache.SetCacheIntoCell(
const ACol, ARow: Integer; ACache: IcxCellInternalCache);
begin
TestIndex(ACol, ARow);
if ACache <> nil then
begin
if FCache[ACol, ARow].InternalCache.Cache <> nil then
SetCacheIntoCell(ACol, ARow, nil);
FCache[ACol, ARow].InternalCache.Cache := ACache;
FCache[ACol, ARow].InternalCache.Index := FInternalCacheList.Add(ACache);
end
else
begin
if FCache[ACol, ARow].InternalCache.Cache <> nil then
begin
FCache[ACol, ARow].InternalCache.Cache := nil;
FInternalCacheList.Delete(FCache[ACol, ARow].InternalCache.Index);
FCache[ACol, ARow].InternalCache.Index := -1;
end;
end;
end;
procedure TcxCustomExportProviderSupportedCellInternalChache.SetEmptyCellsStyle;
var
I, J: Integer;
ACell: TcxCacheItem;
ANewStyle: TcxCacheCellStyle;
begin
for I := 0 to RowCount - 1 do
for J := 0 to ColCount - 1 do
begin
ACell := Cache[J, I];
if not (ACell.DataType in [0,1]) or (ACell.DataSize <> 0) or (GetCellStyle(J, I) = nil) then Continue;
begin
ANewStyle := GetCellStyle(J, I)^;
ANewStyle.FontSize := 1;
SetCellStyle(J, I, ANewStyle);
end;
end;
end;
{ TcxHTMLExportProvider }
procedure TcxHTMLExportProvider.Commit;
var
AStream: TFileStream;
begin
AStream := cxFileStreamClass.Create(cxUnicodeToStr(FileName), fmCreate);
try
CommitHTML(AStream);
finally
AStream.Free;
end;
end;
class function TcxHTMLExportProvider.ExportType: Integer;
begin
Result := cxExportToHTML;
end;
class function TcxHTMLExportProvider.ExportName: string;
begin
Result := cxGetResString(@scxExportToHTML);
end;
procedure TcxHTMLExportProvider.CommitCache(AStream: TStream; AParam: Pointer);
var
ABuffer: string;
ADisplayValue: string;
AStringValue: AnsiString;
AWideStringValue: WideString;
ADoubleValue: Double;
AIntegerValue: Integer;
I, J: Integer;
ACellStyle: PcxCacheCellStyle;
begin
inherited CommitCache(AStream, AParam);
ABuffer := ABuffer + Format('
| 1 then ABuffer := ABuffer + ' COLSPAN=' + IntToStr(Width); if Height > 1 then ABuffer := ABuffer + ' ROWSPAN=' + IntToStr(Height); end else ABuffer := ABuffer + ' | '; if Cache[J, I].InternalCache.Cache <> nil then begin AStream.WriteBuffer(ABuffer[1], dxStringSize(ABuffer)); ABuffer := ''; ADisplayValue := ''; Cache[J, I].InternalCache.Cache.CommitCache(AStream, nil); end else begin if Cache[J, I].DataType = cxDataTypeGraphic then begin SetLength(AStringValue, Cache[J, I].DataSize); GetCellData(J, I, AStringValue[1]); ADisplayValue := GraphicNeeded(dxStringToAnsiString(ExtractFilePath(FileName)), AStringValue); end else if Cache[J, I].DataType = cxDataTypeString then begin if Cache[J, I].DataSize > 0 then begin SetLength(AStringValue, Cache[J, I].DataSize); if GetCellData(J, I, AStringValue[1]) then ADisplayValue := ConvertCRLFSymbols(ConvertSpecialCharacters(dxAnsiStringToString(AStringValue))) end end else if Cache[J, I].DataType = cxDataTypeWideString then begin if Cache[J, I].DataSize > 0 then begin SetLength(AWideStringValue, Cache[J, I].DataSize div SizeOf(Char)); if GetCellData(J, I, AWideStringValue[1]) then ADisplayValue := ConvertCRLFSymbols(ConvertSpecialCharacters(AWideStringValue)) end end else if Cache[J, I].DataType = cxDataTypeDouble then begin if GetCellData(J, I, ADoubleValue) then ADisplayValue := FloatToStr(ADoubleValue) end else if Cache[J, I].DataType = cxDataTypeInteger then begin if GetCellData(J, I, AIntegerValue) then ADisplayValue := IntToStr(AIntegerValue) end end; end; if ADisplayValue = '' then ADisplayValue := cxExportDefaultEmptyString; ABuffer := ABuffer + ADisplayValue + ' | '#13#10; AStream.WriteBuffer(ABuffer[1], dxStringSize(ABuffer)); ABuffer := ''; end; ABuffer := ABuffer + '