生成表格临时文件:
procedure SaveTabDrawFile(PageNumber: Integer;
TabNumber: Integer);
var
TargetFile: TFileStream;
FileFlag: WORD;
PageFlag: Integer;
iLineHeight: Integer;
iTotalLineCount, iMaxLineCountPerPage, iThisPageLineCount: Integer;
iPageCount: Integer;
Count: Integer;
I, J, K: Integer;
TempPChar: array[0..3000] of char;
FileName: string;
strFileDir: string;
sTempStr: String;
begin
strFileDir := MainDir;
// + '/';
if copy(strfiledir, length(strfiledir), 1) <> '/' then
strFileDir := strFileDir + '/';
if not DirectoryExists(strFileDir + 'Temp') then
MkDir(strFileDir +'Temp');
FileName := strFileDir + 'Temp/' + IntToStr(PageNumber) + '.Tmp';
TargetFile := TFileStream.Create(FileName, fmOpenWrite or fmCreate);
try
with TargetFiledo
begin
FileFlag := $AA55;
Write(FileFlag, SizeOf(FileFlag));
PageFlag:=4;
Write(pageFlag, SizeOf(PageFlag));
//iCellHeadLineCount:=1;
// 行高
iLineHeight:= iCellLineHeight;
Write(iLineHeight, SizeOf(iLineHeight));
//总行数
iTotalLineCount:=iTotalCellTextLineCount;
Write(iTotalLineCount, SizeOf(iTotalLineCount));
//每页最大行数
iMaxLineCountPerPage:=iMaxCellTextLineCountPerPage;
Write(iMaxLineCountPerPage, SizeOf(iMaxLineCountPerPage));
//表格总页数
iPageCount:= iCellPageCount;
Write(iPageCount, SizeOf(iPageCount));
//表格页码
Write(TabNumber, SizeOf(TabNumber));
//页码
Write(PageNumber, SizeOf(PageNumber));
//当前页行数
iThisPageLineCount:=iCellThisPageLineCount;
Write(iThisPageLineCount, SizeOf(iThisPageLineCount));
// 每行的属性
for i:=0 to iThisPageLineCountdo
begin
for J:=0 to 6do
begin
case J of
0:
sTempStr:= (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('No').AsString;
1:
sTempStr:= (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('ItemName').AsString;
2:
sTempStr:= (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('MetricUnit').AsString;
3:
sTempStr:= (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('WorkAmount').AsString;
4:
if (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('UnitPrice').AsFloat <> 0 then
sTempStr:= (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('UnitPrice').AsString
else
sTempStr := '';
5:
if (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('Value').AsFloat <> 0 then
sTempStr:= FormatFloat('0.00',(MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('Value').AsFloat)
else
sTempStr := '';
6:
sTempStr:= (MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.FieldByName('Remark').AsString;
end;
Count := Length(sTempStr);
Write(Count, SizeOf(Count));
StrPCopy(TempPChar, sTempStr);
for K:= 0 to Count - 1do
Write(TempPChar[K], 1);
end;
if (i< iThisPageLineCount) then
(MainForm.ActiveMDIChild as TCostCountForm).Table_CostCount.Next;
end;
end;
finally
TargetFile.Free;
end;
end;
读已经生成的临时文件:
procedure LoadTabDrawFile(strFileName: string);
var
TargetFile: TFileStream;
FileFlag: WORD;
PageFlag: Integer;
iLineHeight: Integer;
iTotalLineCount, iMaxLineCountPerPage, iThisPageLineCount: Integer;
iPageCount: Integer;
Count: Integer;
I, J, K: Integer;
TempPChar: array[0..3000] of char;
sTempStr: String;
begin
TargetFile := TFileStream.Create(strFileName, fmOpenRead);
try
with TargetFiledo
begin
Read(FileFlag, SizeOf(FileFlag));
if FileFlag <> $AA55 then
begin
TargetFile.Free;
Application.MessageBox('文件格式不对...', szProgramTitle, MB_OK+MB_ICONERROR);
Exit;
end;
Read(PageFlag, SizeOf(PageFlag));
// 行高
Read(iLineHeight, SizeOf(iLineHeight));
iCellLineHeight:= iLineHeight;
//总行数
Read(iTotalLineCount, SizeOf(iTotalLineCount));
iTotalCellTextLineCount:= iTotalLineCount;
//每页最大行数
Read(iMaxLineCountPerPage, SizeOf(iMaxLineCountPerPage));
iMaxCellTextLineCountPerPage:= iMaxLineCountPerPage;
//总页数
Read(iPageCount, SizeOf(iPageCount));
iCellPageCount:= iPageCount;
//表格页码
Read(iCellPageNumber, SizeOf(iCellPageNumber));
//页码
Read(iPageNumber, SizeOf(iPageNumber));
//当前页行数
Read(iThisPageLineCount, SizeOf(iThisPageLineCount));
iCellThisPageLineCount:= iThisPageLineCount;
//Application.MessageBox(PChar(IntToStr(iThisPageLineCount)), szProgramTitle, MB_OK+MB_ICONWARNING);
// 每行的属性
SetLength(TabRecord, iThisPageLineCount);
for i:=0 to iThisPageLineCount-1do
begin
for j:=0 to 6do
begin
Read(Count, SizeOf(Count));
for K:=0 to Count-1do
Read(TempPChar[K], 1);
TempPchar[Count]:=#0;
sTempStr:= StrPas(TempPChar);
//Application.MessageBox(Pchar(sTempStr), szProgramTitle, MB_OK+MB_ICONWARNING);
//Application.MessageBox(TempPChar, szProgramTitle, MB_OK+MB_ICONWARNING);
case j of
0:
TabRecord.No:= sTempStr;
1:
TabRecord.ItemName:= sTempStr;
2:
TabRecord.MetricUnit:= sTempStr;
3:
TabRecord.WorkAmount:= sTempStr;
4:
TabRecord.UnitPrice:= sTempStr;
5:
TabRecord.Value:= sTempStr;
6:
TabRecord.Remark:= sTempStr;
end;
end;
end;
end;
finally
TargetFile.Free;
end;
end;
生成临时数据库不用我说了,宇宙人都会。