• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 81
  • Last Modified:

How to format Query so resulting excel file is properly formatted.

SO I have a  Query that is used to export a spreadsheet however the columns are not properly formatted causing the user to resize the column manually.  Anything that can be done??

I have attached the output that my program creates.
myexcel.xlsx
0
seamus9909
Asked:
seamus9909
1 Solution
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
When you use TransferSpreadhseet, you do not have the opportunity to manipulate the workbook.  Alternately, you could use code to transfer what you have.  Here is an example that uses CopyFromRecordset and then formats the worksheet when it is done:

http://www.rogersaccesslibrary.com/forum/document-calculated-fields-in-queries_topic619.html
0
 
Dale FyeCommented:
The only way I have done this is to use Excel Automation to open Excel, create a new workbook, paste the query as a recordset into the spreadsheet starting at cell A2 using the CopyFromRecordset method.  Then loop through the recordset fields and take the field caption or Name and paste that into the cells starting at A1.

Then, after that, move from column to column and format the columns using the columns NumberFormat property to set the correct format for each of the columns.  You can also use the columns Autofit property to automatically size each column to fit all text, or can use the ColumnWidth property to manually set the column width.  And, if you need it, you can use the Columns WrapText property to wrap the text in columns that are wider than a specific width.

This method is the only way I have ever been able to ensure that the spreadsheet columns will be in the right format and width.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now