Skip to main content

exporting fields formatted to Excel

Greetings,
How do I create a script that, when exporting to Excel, displays the fields formatted? And the fields with shadows.

Brian Element Fri, 03/21/2025 - 21:07

Here is an example script where IDEA exports an excel file and then the script resizes all the columns in Excel and then changes the font, font size and background color of the first cell.  Let me know if this is enough to get your started.

Option Explicit
Dim sFile As String

Sub Main
	sFile = "D:\My IDEA Documents\IDEA Projects\Samples\Exports.ILB\Sample-Detailed Sales.XLSX"
	Call ExportDatabaseXLSX()	'Sample-Detailed Sales.imd
	Call modifyExcelSheet()
End Sub

Function modifyExcelSheet()
	Dim excel As Object
	Dim oBook As Object
	Dim oSheet As Object
	
	Set excel = CreateObject("Excel.Application")
	excel.Visible = False
	Set oBook = excel.Workbooks.Open(sFile)
	Set oSheet = oBook.Worksheets.Item(1)
	oSheet.Cells.Select
	oSheet.Cells.EntireColumn.AutoFit
	oSheet.Cells(1, 1).Font.Name = "Arial"
	oSheet.Cells(1, 1).Font.Size = 12
	oSheet.Cells(1, 1).Interior.Color = 65535
	
	Set oSheet = Nothing
	oBook.Save
	oBook.Close (True)
	Set oBook = Nothing
	excel.quit
	Set excel = Nothing
End Function


' File - Export Database: XLSX
Function ExportDatabaseXLSX
	Dim db As database
	Dim task As task
	Dim eqn As String
	
	Set db = Client.OpenDatabase("Sample-Detailed Sales.imd")
	Set task = db.ExportDatabase
	task.IncludeAllFields
	eqn = ""
	task.PerformTask sFile, "Database", "XLSX", 1, db.Count, eqn
	Set db = Nothing
	Set task = Nothing
End Function

Brian Element Tue, 03/25/2025 - 16:18

You access the cells by using the oSheet.Cells(1, 1) format, where the first number is the row and the second number is the column.  So to change the heading of the second row you would use oSheet.Cells(1, 2).