How can I Programmatically Import My Data from Excel to DIAdem or Export it From DIAdem to Excel?
Primary Software: DIAdem
Primary Software Version: 9.1
Primary Software Fixed Version: 9.1
Secondary Software: N/A
Problem: In the DIAdem wizards for Excel import and export, I can easily specify which channels to export and which columns to import. My application requires that I import or export all columns/channels programmatically, without using the wizard. How can I go about doing this?
Solution: The following scripts can be used to import all columns or export all channels programmatically:
Read all columns from all Excel sheets into numeric DIAdem channels:
call DataDelAll(1) ' this line is optional
t1=DataDrvUser&"example.xls" ' put the name of your Excel file here
call ExcelCountSheets(t1)
call MsgBoxDisp(str(ExcelSheetCount)&" Sheets, Stat="&str(ExcelStat))
for i=1 to ExcelSheetCount
call MsgBoxDisp(str(i)&": "&ExcelSheets(i))
call ExcelGaugeSheet(t1,ExcelSheets(i),0)
call MsgBoxDisp("stat="&str(ExcelStat) &", chn="&str(ExcelChnCount) &", len="&str(ExcelDataEnd(1)))
if (ExcelChnCount>0 AND ExcelDataEnd(1)>0) then
call ExcelLoad(t1,ExcelSheets(i))
end if
next
Write all DIAdem channels into columns of an Excel sheet:
Before running the script below, generate one configuration file by using the wizard to export all channels to an Excel file, making sure to check the "store" checkbox on the first page of the wizard. This configuration file is necessary so that DIAdem will know where to look when exporting the channels. In the code below, change allexport.stp to the name of the file you created.
t1=DataDrvUser&"example.xls" ' put here the name the Excel file to be written
t2=DataDrvUser&"allexport.stp" ' put here the name the configuration file
call ExcelReadConfig(t2,0) ' reads the configuration file
ExcelChnCount=0
for i=1 to GroupCount ' determine number of channels
ExcelChnCount=ExcelChnCount+GroupChnCount(i)
next
for i=1 to ExcelChnCount ' set variables for configuration
ExcelExpChn(i)=i
next
call ExcelSaveConfig(t2,0) ' writes the configuration file again
call ExcelExport(t1,1,0,t2) ' performs the export using the configuration just written
call MsgBoxDisp(str(ExcelChnCount)&" exported")
Related Links: KnowledgeBase 2JJ8P8AQ: Enabling Excel file Import/Export in DIAdem
Attachments:
Report Date: 12/02/2004
Last Updated: 01/16/2009
Document ID: 3G1D8CL5