以前旧版本测试数据的代码
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, XLSSheetData5, XLSReadWriteII5, Xc12Utils5,
Vcl.Grids, Vcl.StdCtrls, cxGraphics, cxControls, cxLookAndFeels, cxGridExportLink,
cxLookAndFeelPainters, cxStyles, cxCustomData, cxFilter, cxData, MyMsgBox,
cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, cxGridLevel, cxClasses,
cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxGrid, MemDS, DBAccess, Uni;
type
TForm1 = class(TForm)
XLSReadWrite: TXLSReadWriteII5;
btnImport: TButton;
cxGrid1Level1: TcxGridLevel;
cxGrid1: TcxGrid;
dlgSave1: TSaveDialog;
btnExport: TButton;
cxGrid1DBTableView1: TcxGridDBTableView;
cxGridDBColumnGrid1DBTableView1Column1: TcxGridDBColumn;
cxGridDBColumnGrid1DBTableView1Column2: TcxGridDBColumn;
cxGridDBColumnGrid1DBTableView1Column3: TcxGridDBColumn;
unids1: TUniDataSource;
uniqry1: TUniQuery;
btn1: TButton;
uniqry2: TUniQuery;
btn2: TButton;
btn3: TButton;
btn4: TButton;
procedure btnImportClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btnExportClick(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure btn3Click(Sender: TObject);
procedure btn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses UnitDevExpressVCLCustom, UnitUniDAC;
procedure TForm1.btnImportClick(Sender: TObject);
var
iColIndex, iRowIndex: integer;
begin
XLSReadWrite.Filename := 'F:\Import.xlsx';
XLSReadWrite.Read; //此行不能省,否则读取不到数据
cxGrid1DBTableView1.BeginUpdate;
try
with cxGrid1DBTableView1.DataController, XLSReadWrite.Sheets[0] do
begin
RecordCount := LastRow - FirstRow;//必须先定义cxGrid1DBTableView1的行数,否则看不到数据
for iColIndex := FirstCol to LastCol do
begin
for iRowIndex := FirstRow to LastRow do
if iRowIndex <> LastRow then
begin
cxGrid1DBTableView1.Columns[iColIndex].DataBinding.ValueTypeClass := TcxStringValueType;//定义数据类型放在赋值前面,否则看不到数据
Values[iRowIndex, iColIndex] := AsFmtString[iColIndex, iRowIndex + 1];
end;
// ShowMessage('获得Excel表的数据:' + IntToStr(iColIndex));
end;
for iColIndex := FirstCol to LastCol do //解决CXGRID导入EXCEL首行不显示的BUG
begin
cxGrid1DBTableView1.Columns[iColIndex].DataBinding.ValueTypeClass := TcxStringValueType;//定义数据类型放在赋值前面,否则看不到数据
Values[0, iColIndex] := AsFmtString[iColIndex, 1];
cxGrid1DBTableView1.Columns[iColIndex].Caption := '名称';
end;
end;
finally
cxGrid1DBTableView1.EndUpdate;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
MyCxGrid: TMyCxGrid;
begin
MyCxGrid := TMyCxGrid.Create(nil);
MyCxGrid.IniMyCxGrid(cxGrid1DBTableView1);
end;
end.
本文提供了一个使用C++语言通过XLSReadWriteII5库实现的Excel文件导入和导出功能的代码示例。该示例包括了从Excel文件中读取数据并填充到C++应用程序的网格界面,以及将数据从应用程序导出到Excel文件的过程。通过实例代码演示了如何操作Excel表格数据,适用于需要与Excel进行交互的应用开发。
1065

被折叠的 条评论
为什么被折叠?



