ImportExcel
Import an Excel sheet (97-2003 *.xls format) by replacing existing data
int ImportExcel( LPCSTR lpcszFile, int nSheet, XLSReadCntrl * pst )
0 if no error, otherwise <0 error codes, can one of EXCEL_ERR_* enumeration;
EX1
#include <ocGrid.h> //run by //dlgfile g:=*.xls;excel_import fname$; void excel_import(string strFile, bool bCellFormats = true, bool bAutoSize = false) { vector<string> vsSheets; int nn = og_get_excel_sheet_names(strFile, &vsSheets); if(nn <= 0) return; // not a valid Excel file //import to active book WorksheetPage wp = Project.Pages(); if(!wp) return; ExcelImportOptions stR; stR.xlsctrl.m_dwRXC = RXC_VALUE; if(bCellFormats) stR.xlsctrl.m_dwRXC |= RXC_STYLE; stR.xlsctrl.m_nMaxNumEmptyColumnsBeyondLastData = 0; for(int ii = 0; ii < vsSheets.GetSize(); ii++) { Worksheet wks = wp.Layers(vsSheets[ii]); if(!wks) { int nSht = page_find_empty_sheet(wp); if(nSht < 0) nSht = wp.AddLayer(); wks = wp.Layers(nSht); wks.SetName(vsSheets[ii]); } int nErr = wks.ImportExcel(strFile, ii, &stR); if(nErr < 0) { printf("import failed when trying to read %s\n", vsSheets[ii]); return; } if(bAutoSize) autosize_rowcol(wks); } }
To import Excel sheet with *.xlsx format, use Excel COM.
origin.h