Home > Back-end >  Operation Excel problem not set a variable or object With block variables
Operation Excel problem not set a variable or object With block variables

Time:11-16

Procedure output_excel_file (file_path: string; Report_type: Toutput_report_type; Report_CDS: TADOQUERY);
Var
Ecloum Erow, row1, row2, I: integer;
Excel_application: variant;
StrFormat: OleVariant;
The begin


Try
Excel_application:=createoleobject (' Excel. Application);
Excel_application. Workbooks. Add;

Except,
Application. MessageBox (' excel is not installed, please check ', 'worng, mb_iconerror + mb_ok);
Excel_application. Quit;
Excel_application:=the unassigned;
exit;
end;
.
.

Excel_application. Workbooks [1]. The SaveAs (file_path);

end;

Tools: Delphi2010
Environment: Windows 7 office2010 plus

Run to:
Excel_application. Workbooks [1]. The SaveAs (file_path);
When;
An error
Runtime error "91"
Not set a variable or object With block variable
Please help take a look at how to refuse, thank you!


CodePudding user response:

Attention,,,,,,,,,

CodePudding user response:

Procedure TSearchForm. Ygnsr_DcbtnClick (Sender: TObject);
Var
Excel: Variant;
WorkBook: OleVariant;
SavePath: OleVariant;
I, c: integer;
StatePanel: TMiniTitlePanel;
The begin
If Ygnsr_Grid. RowCount=0 then
The begin
MiniToolTip1. ShowBalloonTip (Ygnsr_Grid. Handle, 2, 'prompt', 'beyond the export data! ');
The Exit;
end;
DocSaveDialog. Title:='saved in';
DocSaveDialog. DefaultExt:='XLSX';
DocSaveDialog. Filter:='| * XLSX EXCEL document;
If DocSaveDialog. Execute then
SavePath:=DocSaveDialog FileName
The else
The Exit;

StatePanel:=TMiniTitlePanel. Create (nil);
StatePanel. Parent:=Ygnsr_Grid;
StatePanel. Width:=185;
StatePanel. Height:=32;
StatePanel. Left:=(StatePanel. Parent. Width - StatePanel. Width) div 2;
StatePanel. Top:=(StatePanel. Parent. Height - StatePanel. Height) div 2;
StatePanel. ShowTitle:=False;
StatePanel. Caption:='progress: 0/+ IntToStr (Ygnsr_Grid. RowCount);
StatePanel. The Font. Color:=clBlue;
StatePanel. Color:=clSkyBlue;
StatePanel. Show;
StatePanel. Repaint;
The Self. The Repaint;
Try
Excel:=CreateOleObject (' Excel. Application);
Try
Excel. Visible:=False;
WorkBook:=Excel WorkBooks. Add;
Try
. Excel WorkSheets [1]. Activate;

Excel. ActiveSheet. Columns [1]. The HorizontalAlignment:=2;//the left
Excel. ActiveSheet. Columns [1]. ColumnWidth:=12;
Excel. Cells [1, 1]. The Value:='employee names;
Excel. ActiveSheet. Columns [2]. The HorizontalAlignment:=4;//right centered alignment 3 to
Excel. ActiveSheet. Columns [2]. ColumnWidth:=12;
Excel. Cells [1, 2]. The Value:='1 month;
Excel. ActiveSheet. Columns [3]. The HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [3]. ColumnWidth:=12;
Excel. Cells [1, 3]. The Value:='2 monthly wages;
Excel. ActiveSheet. Columns [4]. The HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [4]. ColumnWidth:=12;
Excel. Cells [1, 4]. The Value:='3 monthly wages;
Excel. ActiveSheet. Columns [5]. The HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [5]. ColumnWidth:=12;
Excel. Cells [1, 5). The Value:='4 monthly wages;
Excel. ActiveSheet. Columns [6]. The HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [6]. ColumnWidth:=12;
Excel. Cells [1, 6]. The Value:='5 monthly wages;
Excel. ActiveSheet. Columns [7]. The HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [7]. ColumnWidth:=12;
Excel. Cells [1, 7]. The Value:='6 monthly wages;
Excel. ActiveSheet. Columns [8]. The HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [8]. ColumnWidth:=12;
Excel. Cells [1]. The Value:='7 monthly wages;
Excel. ActiveSheet. Columns [9]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [9]. ColumnWidth:=12;
Excel. Cells [1, 9]. Value:='8 month';
Excel. ActiveSheet. Columns [10]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [10]. ColumnWidth:=12;
Excel. Cells [1, 10]. Value:='9 month';
Excel. ActiveSheet. Columns [11]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [11]. ColumnWidth:=12;
Excel. Cells [1, 11]. Value:='10 monthly wages;
Excel. ActiveSheet. Columns [12]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [12]. ColumnWidth:=12;
Excel. Cells [1, 12]. Value:='11 month';
Excel. ActiveSheet. Columns [13]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [13]. ColumnWidth:=12;
Excel. Cells [1, 13]. Value:='12 monthly wages;
Excel. ActiveSheet. Columns [14]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [14]. ColumnWidth:=12;
Excel. Cells [1, 14]. Value:='bonuses;
Excel. ActiveSheet. Columns [15]. HorizontalAlignment:=4;
Excel. ActiveSheet. Columns [15]. ColumnWidth:=12;
Excel. Cells [1]. The Value:='total';
StatePanel. Caption:='task processing... 0/'+ IntToStr (Ygnsr_Grid RowCount);
StatePanel. Update;
For I:=1 to Ygnsr_Grid RowCount do
For c:=1 to Ygnsr_Grid. Titles. Count the do
The begin
Excel. Cells (I + 1, c). The Value:=Ygnsr_Grid. Cells [I - c - 1, 1);

StatePanel. Caption:='task processing... '+ IntToStr (I) +'/' + IntToStr (Ygnsr_Grid. RowCount);
StatePanel. Update;
end;

StatePanel. Caption:='are saved... ';
StatePanel. Repaint;
WorkBook. SaveAs (SavePath); nullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related