Subject: CnXlsWriter更新一个bug [Print This Page]
Author:
solokey Time: 2010-6-2 15:10 Subject: CnXlsWriter更新一个bug
没找到老刘,所以就发在这里了.管理员看到了更新一下吧.
修改这个函数即可.以前的代码会搞错int64和extended,因为variant里貌似没这个类型.现在把用string写入varriant的整型和浮点型,都在前面加个',防止被科学计数...
procedure TCnXlsWriter.SetCells(const ACol: Byte; const ARow: Word; const Value: Variant);
var
aStr: string;
aInt: Integer;
aFloat: Double;
aCode: Integer;
begin
case VarType(Value) of
varSmallint, varInteger, varByte:
XlsWriteCellRk(FStream, ACol, ARow, Value);
varSingle, varDouble, varCurrency:
XlsWriteCellNumber(FStream, ACol, ARow, Value);
varString, {$IFDEF DELPHI2009_UP} varUString, {$ENDIF} varOleStr:
begin
Val(aStr, aInt, aCode);
if aCode = 0 then
begin
XlsWriteCellLabel(FStream, ACol, ARow, '''' + aStr);
Exit;
end;
Val(aStr, aFloat, aCode);
if aCode = 0 then
begin
XlsWriteCellLabel(FStream, ACol, ARow, '''' + aStr);
Exit;
end;
XlsWriteCellLabel(FStream, ACol, ARow, Value);
end;
varDate:
XlsWriteCellLabel(FStream, ACol, ARow, DateTimeToStr(Value));
else
XlsWriteCellBlank(FStream, ACol, ARow);
end;
end;
Author:
Passion Time: 2010-6-16 20:43
好的,非常感谢。已经提交入SVN。
Author:
solokey Time: 2010-8-9 00:24
貌似还是得更新一个,2010下的问题.这种文件格式貌似不支持Unicode的双字节字符串.
更新一个函数声明:
procedure XlsWriteCellLabel(XlsStream: TStream; const ACol: Byte; const ARow: Word;
const AValue: AnsiString);
再继续更新那个函数:
procedure TCnXlsWriter.SetCells(const ACol: Byte; const ARow: Word; const Value: Variant);
var
aStr: AnsiString;
aUStr: WideString;
aInt: Integer;
aFloat: Double;
aCode: Integer;
begin
case VarType(Value) of
varSmallint, varInteger, varByte:
XlsWriteCellRk(FStream, ACol, ARow, Value);
varSingle, varDouble, varCurrency:
XlsWriteCellNumber(FStream, ACol, ARow, Value);
varString, varOleStr:
begin
aStr := VarToStr(Value);
Val(aStr, aInt, aCode);
if aCode = 0 then
begin
XlsWriteCellLabel(FStream, ACol, ARow, '''' + aStr);
Exit;
end;
Val(aStr, aFloat, aCode);
if aCode = 0 then
begin
XlsWriteCellLabel(FStream, ACol, ARow, '''' + aStr);
Exit;
end;
XlsWriteCellLabel(FStream, ACol, ARow, Value);
end;
{$IFDEF DELPHI2009_UP}
varUString:
begin
aUStr := VarToWideStr(Value);
aStr := WideCharToString(PWideChar(aUStr));
XlsWriteCellLabel(FStream, ACol, ARow, aStr);
end;
{$ENDIF}
varDate:
XlsWriteCellLabel(FStream, ACol, ARow, DateTimeToStr(Value));
else
XlsWriteCellBlank(FStream, ACol, ARow);
end;
end;
另外,这样写的话,d2010会报Warning,因为我手头没这个高科技的2010...谁来试下?
目前的代码双字节的问题是解决了..就是会报Warning,不爽啊.
Author:
Passion Time: 2010-8-9 07:43
提交了。感谢。
Warning的问题,加上AnsiString强制类型转换就行。具体代码可在SVN上看看?
Welcome to CnPack Forum (http://bbs.cnpack.org/) |
Powered by Discuz! 5.0.0 |