************************************************************ * FUNCTION CheckXLSHeaders() ************************************************************ * Author............: VCS Developers Team * Project...........: Visual Collections System * Created...........: 01/01/2000 17:00:00 * Copyright.........: (c) Jzanus, 2006 *) Description.......: Checks if all columns are present in Excel file * Calling Samples...: CheckXLSHeaders(getfile('XLS'),"STATUS;BATCH #",3) * Parameter List....: tcInputFile, tcTestString, tnStartFromRow * Major change list.: function CheckXLSHeaders lparameters tcInputFile, tcTestString, tnStartFromRow if empty(m.tcInputFile) tcInputFile = getfile('xls','Select XLS', 'Select', 0, ; 'Select XLS to check Headers Info') if empty(m.tcInputFile) return "Input file is not passed" endif endif if empty(m.tcTestString) tcTestString = inputbox("Enter Headers to test", ; "Enter Headers to test in XLS file", "STATUS;BATCH #") if empty(m.tcTestString) return "Test string is not passed" endif endif if empty(m.tnStartFromRow) tnStartFromRow = 1 endif local OleApp, lcMsg, lcCellValue, lcStr, lcRange, ; lnCols, lnNumSheets, lnDoneSheets, lnI, loSheet, ; loErr, lnSheet, loRangeProblem *-- Create column name array local array laFieldNames[1], laTestVals[1] lcMsg = "" lcCellValue = "" lnDoneSheets = 0 try OleApp = createobject("Excel.Application") *-- Open XLS File OleApp.application.WorkBooks.open(m.tcInputFile) lnNumSheets = OleApp.application.application.WorkBooks(1).Sheets.count for lnSheet = 1 to m.lnNumSheets *-- Select individual sheet from opened XLS File loSheet = OleApp.application.application.WorkBooks(1).Sheets(m.lnSheet) with loSheet .select lcStr = OleApp.application.ActiveSheet.name ** Do this only for non-SUMMARY sheets in the spreadsheet if !("SUMMARY" $ upper(m.lcStr)) lnDoneSheets = m.lnDoneSheets + 1 ** Delete first N unused rows (help by Sergey Berezniker) if m.tnStartFromRow > 1 .range("A1" , "A" + ; transform(m.tnStartFromRow)).EntireRow.delete() endif lnCols = .UsedRange.columns.count dimension laFieldNames[m.lnCols, 1] for lnI = 1 to m.lnCols lcCellValue = .Cells(1,m.lnI).value laFieldNames[m.lnI] = upper(alltrim(m.lcCellValue)) next lnCols = alines(laTestVals, m.tcTestString, 1, ";") for lnI = 1 to m.lnCols if ascan(laFieldNames, laTestVals[m.lnI],1,-1,1,5) = 0 lcMsg = laTestVals[m.lnI] + ; " column is not found in " + m.tcInputFile exit endif next endif endwith next OleApp.DisplayAlerts = .f. OleApp.quit catch to loErr lcMsg = Log_Error(m.loErr) endtry OleApp = null return m.lcMsg endfunc