Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change the variable name
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01108038
Message ID:
01108481
Vues:
14
>i am importing into xle
>i want after imporitng into excle level=Level or LEVEL(only upper name of varialbe)
>
>SELECT Examtran.lcode AS level, Examtran.sec AS sec,;
>  Examtran.descr AS month, Examtran.year AS year, Examtran.code AS code,;
>  Examtran.name AS name, Examtran.tmax AS total,;
>  Examtran.tmin AS passmarks, Examtran.tobt AS stu_obt,;
>  Examtran.asrank AS rank, Examtran.grade AS grade, Examtran.perc;
> FROM ;
>     examtran;
> WHERE  Examtran.year = ( 2005 );
> INTO TABLE result
>
>
>
>SELECT result
>brows
>Copy to d:\projects\school\result.xls type xls
>loExcel = createobject("Excel.Application")
>loWorkbook = loExcel.workbooks.open("d:\projects\school\result.xls")
>loSheet = loWorkbook.sheets(1) && or pass the name of your sheet as a string!
>loExcel.Visible = .T. && display Excel
>
Here are the functions I recently wrote with the help of Borislav Borissov and Cetin Basoz:
************************************************************
*  FUNCTION DBFToExcel()
************************************************************
*  Author............: VCS  Developers Team (Nadya Nosonovsky)
*  Project...........: Visual Collections System
*  Created...........: 03/03/2006  10:05:42
*  Copyright.........: (c) Jzanus, 2006
*) Description.......:
*  Calling Samples...: DbfToExcel(m.lcXLSFile, @laHeader_Info, "Batch Statistics")
*  Parameter List....: tcXLSFileName, taHeader_Info, tcTitle
*  Major change list.:
function DBFToExcel
lparameters tcXLSFileName, taHeader_Info, tcTitle
external array taHeader_Info
* This function assumes, that the output table (cursor) is currently opened
*-- Generate output to XLS File

local loExcel, lnI, loSheet, lnK, lcError, lnLines
lcError = ""

local array laTitle[1]
lnLines = alines(laTitle, m.tcTitle)

#include Excel.h
#define xlPart   2

*-- Add Header into XLS File
try
	copy to (m.tcXLSFileName) type xl5
*-- Create Ole Automation with Excel
	loExcel=createobject("Excel.Application")
*-- Open XLS File
	loExcel.application.WorkBooks.open(m.tcXLSFileName)
	loExcel.DisplayAlerts = .f.

	for lnI = 1 to loExcel.application.application.WorkBooks(1).Sheets.count
*-- Select individual sheets from open XLS File
		loSheet = loExcel.application.application.WorkBooks(1).Sheets(m.lnI)

** Delete the column headers from Excel (first row)
		loSheet.rows("1").delete(xlShiftDown)

** Insert lines with Title + 4 empty rows for the column headers
		loSheet.rows("1:"+ alltrim(str(m.lnLines + 4))).insert(xlShiftDown)
		with loSheet.range("1:" + alltrim(str(m.lnLines))).font
			.color = 8388736 && rgb(255,0,0)
			.size  = 14
			.Bold  = .t.
			.name = 'Tahoma'
		endwith

		with loSheet.range(alltrim(str(m.lnLines + 1)) + ":" + alltrim(str(m.lnLines + 4))).font
*  .Color = Rgb(255,0,0)
			.size  = 11
			.Bold  = .t.
			.name = 'Tahoma'
		endwith

*!*			With loSheet.Range("1:2").Borders
*!*			  .Weight = xlMedium
*!*			  .LineStyle = xlContinuous
*!*			 Endwith
		for lnK = 1 to m.lnLines
			loSheet.Cells(m.lnK, 1).value = laTitle[m.lnK]
		next

		for lnK = 1 to alen(taHeader_Info,1)
			loSheet.Cells(2 + m.lnLines, m.lnK).value = taHeader_Info[m.lnK,1]
			loSheet.Cells(3 + m.lnLines,m.lnK).value = taHeader_Info[m.lnK,2]

			if !empty(taHeader_Info[m.lnK,3]) && There is format information
				loRange = loSheet.UsedRange.Offset(m.lnLines + 4,0) && we don't want to apply format for header rows
				loRange.columns[m.lnK].NumberFormat = taHeader_Info[m.lnK,3]
			endif

			if !empty(taHeader_Info[m.lnK,4]) && There is Column Width
				loSheet.columns[m.lnK].select
				loSheet.columns[m.lnK].columnwidth = taHeader_Info[m.lnK,4]
			endif
		next
	next

** Made the Totals row in bold and Green highlight
	loExcel.range([A1], loExcel.selection.SpecialCells(xlLastCell)).select
	loExcel.selection.FormatConditions.delete
	loExcel.selection.FormatConditions.add(xlExpression,, '=UPPER(Left($A1,5))="TOTAL"')

	with loExcel.selection.FormatConditions(1)
		.font.Bold = .t.
		.Interior.ColorIndex = 4
	endwith
	loExcel.save()

catch to loError
	lcError = Log_Error(m.loError)
finally
	if vartype(m.loExcel) = 'O'
		loExcel.DisplayAlerts = .t. && Restore back
		loExcel.quit
	endif
endtry

if not empty(m.lcError)
	=ErrorMsg(m.lcError)
endif

return m.lcError
endfunc
************************************************************
*  Function CombineExcelFiles
************************************************************
*  Author............: VCS  Developers Team
*  Project...........: Visual Collections System
*  Created...........: Craig Boyd 3/6/2006  23:55:50
*  Copyright.........: (c) Jzanus, 2006
*) Description.......:
*  Calling Samples...: DIMENSION aXLSFiles(3)
*!*					aXLSFiles(1) = "C:\temp1.xls"
*!*					aXLSFiles(2) = "C:\temp2.xls"
*!*					aXLSFiles(3) = "C:\temp3.xls"
*!*					CombineExcelFiles(@aXLSFiles, "C:\XLSCombined.xls")
*  Parameter List....:
*  Major change list.:
function CombineExcelFiles (taXLSFiles, tcDestination, tlDeleteOriginal)
external array taXLSFiles
local loExcel as Excel.application, ;
	loWorkBook as Excel.Worksbook, ;
	loWorkSheet , ;
	lnCounter, lcWorkSheetCaption, lcError, ;
	lcValidChars

lcError = ""

try
	lcValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
	loExcel = newobject("Excel.Application")
	with loExcel
		.ScreenUpdating = .f.
		.DisplayAlerts = .f.
		.WorkBooks.add()
		lnCounter = 0

** Delete all existing worksheets except 1
		for each loWorkSheet in .WorkBooks(1).WorkSheets
			lnCounter = m.lnCounter + 1
			if m.lnCounter > 1
				loWorkSheet.delete
			endif
		endfor

		for lnCounter = 1 to alen(taXLSFiles,1)
			if file(taXLSFiles[m.lnCounter])
				lcWorkSheetCaption = juststem(taXLSFiles[m.lnCounter])
				loWorkBook = .WorkBooks.open(taXLSFiles[m.lnCounter])
				loWorkBook.WorkSheets(1).copy(null, ;
					.WorkBooks(1).WorkSheets(.WorkBooks(1).WorkSheets.count))
				.WorkBooks(1).ActiveSheet.name = ;
					right(alltrim(chrtran(m.lcWorkSheetCaption, ;
					chrtran(m.lcWorkSheetCaption,m.lcValidChars,"")," ")), 31) &&loWorkBook.Name
				loWorkBook.close(.f.) && Don't save changes
				if m.tlDeleteOriginal
					erase (taXLSFiles[m.lnCounter])
				endif
			endif
		endfor
** Remove the first original sheet from (Sheet1)
		.WorkBooks(1).WorkSheets(1).delete

		.WorkBooks(1).saveas(m.tcDestination)
		.ScreenUpdating = .t.
		.DisplayAlerts = .t.
	endwith

catch to loError
	lcError = Log_Error(m.loError)
finally
	if vartype(m.loExcel) = 'O'
		with loExcel
			.ScreenUpdating = .t.
			.DisplayAlerts = .t.
			.quit()
		endwith
	endif
endtry

if not empty(m.lcError)
	=ErrorMsg(m.lcError)
endif

return m.lcError

endfunc
First function allows you to add custom headers for the columns (the headers should be defined in the array - 1 & 2 columns) and the second function allows to combine multiple tables into one Excel file. The second function was created with the help of Craig Boyd. (actually, I just slightly modified his original code)
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform