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

S

sheng12

Unregistered / Unconfirmed
GUEST, unregistred user!
在delphi 2010 中设置excel单元格的格式设置为文本为什么用xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';设置后用EXCEL打开看,格式成了 64 而不是 @ 这是为什么呀这语句在delphi 7中使用正常。。。在delphi2010中应该怎么写呀
 
试试这样呢Excel := CreateOLEObject('Excel.Application');Excel.ActiveSheet.Rows.numberformat := '@';
 
没有用。。用Sheet.cells[iCount + 1, jCount + 1] := stringgrid1.Cells[jCount,iCount];写入的数字还是显示成了64
 
试了一下,用其他的如:A,&,~...XLApp.Workbooks[1].WorkSheets['sheet1'].Columns[2].NumberFormatLocal := 'A';没有问题
 
用了'A'结果都显示成了65。。。用了'B'结果都显示成了66。。。这是为什么呀
 
贴完整代码看看,估计代码处理有问题,建议不要直接赋值可以 S := stringgrid1.Cells[jCount,iCount]; Sheet.cells[iCount + 1, jCount + 1] := S; 在执行过程中,查看S的值是多少
 
procedure TForm1.Button2Click(Sender: TObject);variCount, jCount: Integer;XLApp: Variant;Sheet: Variant;beginbutton1.Enabled:=false;button2.Enabled:=false;if not VarIsEmpty(XLApp) thenbeginXLApp.DisplayAlerts := False;XLApp.Quit;VarClear(XLApp);end;tryXLApp := CreateOleObject('Excel.Application');exceptExit;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 dobeginfor 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
 
excel是什么版本?
 
excel是2007
 
终于解决了,将xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@';改为xls.ActiveSheet.Columns[2].NumberFormatlocal:= '@ ';后正常,汗!!!要在@后加一个空格。。。
 
多人接受答案了。
 
顶部