delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

Description of your first forum.

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期五, 2010年1月15日 13:31


delphi 2010 中设置excel单元格的格式设置为文本
为什么用
xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';
设置后用EXCEL打开看,格式成了  64 而不是 @
这是为什么呀
这语句在delphi 7中使用正常。。。
在delphi2010中应该怎么写呀
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子zhengrong117 » 星期五, 2010年1月15日 13:59


试试这样呢
Excel := CreateOLEObject('Excel.Application');
Excel.ActiveSheet.Rows[i].numberformat := '@';
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期五, 2010年1月15日 14:31


没有用。。
用Sheet.cells[iCount + 1, jCount + 1] := stringgrid1.Cells[jCount,iCount];写入的数字还是显示成了64
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子japhe » 星期五, 2010年1月15日 18:10


试了一下,用其他的如:A,&,~...
XLApp.Workbooks[1].WorkSheets['sheet1'].Columns[2].NumberFormatLocal := 'A';
没有问题
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期三, 2010年1月20日 08:23


用了'A'
结果都显示成了65。。。
用了'B'
结果都显示成了66。。。
这是为什么呀
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子GodIsWrong » 星期三, 2010年1月20日 09:01


贴完整代码看看,估计代码处理有问题,建议不要直接赋值
可以 S := stringgrid1.Cells[jCount,iCount]; Sheet.cells[iCount + 1, jCount + 1] := S; 在执行过程中,查看S的值是多少
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期三, 2010年1月20日 09:22


procedure TForm1.Button2Click(Sender: TObject);
var
iCount, jCount: Integer;
XLApp: Variant;
Sheet: Variant;
begin
button1.Enabled:=false;
button2.Enabled:=false;
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
VarClear(XLApp);
end;
try
XLApp := CreateOleObject('Excel.Application');
except
Exit;
end;
XLApp.WorkBooks.Add;  
XLApp.WorkBooks[1].WorkSheets[1].Name := 'sheet1';
Sheet := XLApp.Workbooks[1].WorkSheets['sheet1'];
stringgrid1.Row := 0;
xlapp.ActiveSheet.Columns[2].numberformat := '@';
sheet.Columns[4].NumberFormatlocal := '@';
for iCount := 0 to stringgrid1.RowCount - 1 do
begin
for jCount := 0 to stringgrid1.ColCount - 1 do
   Sheet.cells[iCount + 1, jCount + 1] := stringgrid1.Cells[jCount,iCount];
stringgrid1.Row := iCount;
application.ProcessMessages;
end;

XLApp.ActiveWorkbook.SaveAs(FileName:='1.xls');
Screen.Cursor := crDefault;
XLApp.quit;
button1.Enabled:=true;
button2.Enabled:=true;
end;

上面用
xlapp.ActiveSheet.Columns[2].numberformat := '@';
sheet.Columns[4].NumberFormatlocal := '@';
写出来的都是一样。。。显示为64
在过程中加了变量看了一下S;=sheet.Columns[4].NumberFormatlocal 的值,S就是64
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子delhpi » 星期三, 2010年1月20日 17:41


excel是什么版本?
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期四, 2010年1月21日 16:02


excel是2007
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期四, 2010年1月21日 16:12


终于解决了,将
xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';
改为
xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@ ';
后正常,汗!!!要在@后加一个空格。。。
 
 
 

delphi 2010 中xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';为什么会变成64?

帖子sheng12 » 星期四, 2010年1月21日 16:15


多人接受答案了。