Now I have export data from a table in excel format! but I can only export data in text file. It's there another way.
Here is my export ctrl:
main()
{
string timeS;
timeS = year(getCurrentTime())+"-"+month(getCurrentTime())+"-"+day(getCurrentTime())+" "+hour(getCurrentTime())+" "+minute(getCurrentTime())+" "+second(getCurrentTime());
TABLE1.writeToFile("D:/" + timeS + " ErreZhengqi.CSV", TABLE_WRITE_ALL_COLUMNS | TABLE_WRITE_COLUMN_HEADER , "; ");
system("explorer.exe D:\\\\");
}
How to export data from table in excel format?
- BenjaminSeeker
- Posts:30
- Joined: Wed Jan 12, 2011 9:51 am
How to export data from table in excel format?
- aorange
- Posts:147
- Joined: Thu Nov 04, 2010 10:07 am
Re: How to export data from table in excel format?
It is possible to write data to Excel using ComObjects but it isn't the most straight forward thing in the world, check out the createComObject() example in the help file to get started. I'll see if I can find a real-life example in one of my old projects to help you out.
One thing to be mindful of (which was the case in 3.10 at least) is that the CTRL and UI managers have different implementations of COM which can make it tricky if you write and test all your functions using a UI and then want to move them to a CRTL manager.
One thing to be mindful of (which was the case in 3.10 at least) is that the CTRL and UI managers have different implementations of COM which can make it tricky if you write and test all your functions using a UI and then want to move them to a CRTL manager.
- aorange
- Posts:147
- Joined: Thu Nov 04, 2010 10:07 am
Re: How to export data from table in excel format?
Can't find a good example of how to write to an Excel file but here is one on how to read from one, some things could have been done a little better but this was written a long time ago so bear with me 
Code: Select all
int ReadExcelFile(string strFileName, dyn_dyn_anytype &ddaFileContent)
//*********************************************************************************
// Extract the complete content of the Excel file requested in the first parameter
// using the COM application interface provided by MS.
// Returns the file content in a dyn_dyn_any_type.
// Arguments required are:
// - strFileName, full path of the file to be extracted
// - ddaFileContent, a dyn_dyn_anytype variable to receive the information
//*********************************************************************************
{
if(isfile(strFileName))
{
dyn_string dsXlCol;
dsXlCol[1] = "A";
dsXlCol[2] = "B";
dsXlCol[3] = "C";
dsXlCol[4] = "D";
dsXlCol[5] = "E";
dsXlCol[6] = "F";
dsXlCol[7] = "G";
dsXlCol[8] = "H";
dsXlCol[9] = "I";
dsXlCol[10] = "J";
dsXlCol[11] = "K";
dsXlCol[12] = "L";
dsXlCol[13] = "M";
dsXlCol[14] = "N";
dsXlCol[15] = "O";
dsXlCol[16] = "P";
dsXlCol[17] = "Q";
dsXlCol[18] = "R";
dsXlCol[19] = "S";
dsXlCol[20] = "T";
dsXlCol[21] = "U";
dsXlCol[22] = "V";
dsXlCol[23] = "W";
dsXlCol[24] = "X";
dsXlCol[25] = "Y";
dsXlCol[26] = "Z";
idispatch xl;
idispatch xlWorkbooks;
idispatch xlWorkbook;
idispatch xlWorkSheets;
idispatch xlWorksheet;
idispatch xlRange;
anytype aRaw;
dyn_string dsTimeStamps;
dyn_float dfVals;
int intRows;
int intColumns;
/* Open Excel Object */
xl = createComObject("Excel.Application"); // Create the application interface
if(xl != 0)
{
xl.visible = FALSE; // Keep the file hidden from the user
xlWorkbooks = xl.Workbooks; // Get the Workbooks collection
xlWorkbook = xlWorkbooks.Open(strFileName); // Call the open event (inherited from the WorkbookEvents_Event)
xlWorkSheets = xl.Worksheets; // Get the Worksheets collection
xlWorksheet = xlWorkSheets.Item(1); // Item is a property inherited from Sheets
xlRange = xlWorksheet.UsedRange;
intRows = xlRange.Rows.Count; // Get the number of used rows
intColumns = xlRange.Columns.Count; // Get the number of used columns
for(int i = 1; i- BenjaminSeeker
- Posts:30
- Joined: Wed Jan 12, 2011 9:51 am
Re: How to export data from table in excel format?
Now I have another idea.
The ASCII manager can export DPE info into a .dpl file.
Then the .dpl file can be opened by Excel.
So I think maybe I can use the script to export the table data into a .csv file.
I think it will work.
So I will try it later.
The ASCII manager can export DPE info into a .dpl file.
Then the .dpl file can be opened by Excel.
So I think maybe I can use the script to export the table data into a .csv file.
I think it will work.
So I will try it later.
- aorange
- Posts:147
- Joined: Thu Nov 04, 2010 10:07 am
Re: How to export data from table in excel format?
I suppose it depends on what kind of data you want to export, if its DP/DPE parameterisation, etc. then I'd use the ASCII manager. If, on the other hand, it is process data you want to be able to recursively manipulate in Excel then I would use the method above.
If you only need to export process data as a one off then I would look at using something like Labour Values or Correction Values and manually copy/paste data into a spreadsheet.
If you only need to export process data as a one off then I would look at using something like Labour Values or Correction Values and manually copy/paste data into a spreadsheet.