Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append From (spreadsheet): column names?
Message
 
 
To
09/07/2006 09:52:13
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01134756
Message ID:
01134779
Views:
17
>If you export to a spreadsheet using the command:
>
>EXPORT TO MySpreadsheet TYPE XLS (or some other spreadsheet type)
>
>and then later, in another program, you import data from that same spreadsheet into a cursor using the statement:
>
>APPEND FROM MySpreadsheet TYPE XLS (or some other spreadsheet type)
>
>is there any way to get the column names from the spreadsheet that that were created in the first step when the spreadsheet was created?
>
>I know that for character columns, the column name appears in the first row, but all numeric columns appear as 0. Is there some way to query the spreadsheet to determine the column names?
>
>I need to to do this in order to check if the user imported an incorrect spreadsheet (which I would know because the spreadsheet would not have the correct columns) or if the user moved the columns around between the time the spreadsheet was created and the time it was re-imported.
>
>TIA

See if this funciton can be of any use:
************************************************************
*  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
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform