I m a new Axapta developer frm Turkey.
I ve some difficulties while exporting data to excel
from code.
Here is my code (class method) :
-------------------------------------------------
void exportToExcel()
{
SysExcelApplication app;
SysExcelWorksheet Worksheet;
SysExcelWorksheets Worksheets;
SysExcelWorkbooks Workbooks;
SysExcelWorkbook Workbook;
SysExcelRange SysExcelRange;
SysExcelCell RCell;
SysExcelCells Cells;
myTable rs;
COMVariant COMVariant1;
int i;
;
#excel
app =
SysExcelApplication::construct();
Workbooks = app.Workbooks();
Workbook = Workbooks.Add();
Worksheets = Workbook.worksheets();
Worksheet = Worksheets.itemFromNum(1);
Worksheet.name("myTable");
Cells = Worksheet.Cells();
i = 1;
// Construct first row of the excel worksheet
(table field names)
RCell = Cells.Item(i, 1);
RCell.Value("GroupId");
RCell = Cells.Item(i, 2);
RCell.Value("Description");
RCell = Cells.Item(i, 3);
RCell.Value("FieldInt");
RCell = Cells.Item(i, 4);
RCell.Value("FieldReal");
RCell = Cells.Item(i, 5);
RCell.Value("FieldDate");
// Export all table data to excel worksheet
while select rs
{
i++;
RCell = Cells.Item(i, 1);
RCell.Value(rs.GroupId);
RCell = Cells.Item(i, 2);
RCell.Value(rs.Description);
RCell = Cells.Item(i, 3);
RCell.Value(rs.FieldInt);
RCell = Cells.Item(i, 4);
RCell.Value(rs.FieldReal);
RCell = Cells.Item(i, 5);
RCell.Value(date2str
(rs.FieldDate,123,2,2,2,2,2));
}
if (Winapi::fileExists("C:\\myExcel.xls"))
Winapi::deleteFile("C:\\myExcel.xls");
Workbook.saveAs("C:\\myExcel.xls");
Workbooks.close();
}
-------------------------------------------------
Firstly, I want to construct first row of the excel
worksheet dynamically by getting the number and the
name of the myTable's fields. How to get them?
The method that i wrote above is a method of
"myClass". I create a new instance of "myClass" in a
button click, then I call the method above. I wish
also to declare a class variable (in the class
declaration) and wish to set this variable the path
"C:\\myExcel.xls" in the button click. After that, i
ll use this variable in the method written above.
Can anybody help me?
Code examples will be more useful.
Thanks in advance.
Baran
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/development-axapta/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.