How to create an excel file template via vb.net?
Hi,
I have a program that needs to create a downloadable excel template with the following headers on the first row named, name, age, gender. And I also want the template to only have 1 sheet on it.
how can I create a sample template using vb.net code?
Thanks
jbutardo
Junior Poster in Training
74 posts since Jan 2012
Reputation Points: 8
Solved Threads: 2
Skill Endorsements: 0
Since I see you have some experience generating an Excel file from VB.NET, I'll just post the "meat"
Dim wb As Workbook = excel.Workbooks.Add(Type.Missing)
Dim ws As Worksheet = wb.Worksheets(1)
Dim rowCurrent As Range = ws.Rows(1, Missing.Value)
CType(rowCurrent.Cells(1, 1), Range).Value2 = "Name"
CType(rowCurrent.Cells(1, 2), Range).Value2 = "Age"
CType(rowCurrent.Cells(1, 3), Range).Value2 = "Gender"
' brutal (there is probably a better way...)
While (wb.Worksheets.Count > 1)
wb.Worksheets(wb.Worksheets.Count).Delete()
End While
' store the template where templates go.
Dim strAppDataDir As String = Environment.GetEnvironmentVariable("APPDATA")
Dim strTemplateDir As String = strAppDataDir + "\Microsoft\Templates\Templ1.xlt"
wb.SaveAs(strTemplateDir, XlFileFormat.xlTemplate)
' be sure to close the workbook and Quit out of Excel
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Since I see you have some experience generating an Excel file from VB.NET, I'll just post the "meat"
Dim wb As Workbook = excel.Workbooks.Add(Type.Missing)
Dim ws As Worksheet = wb.Worksheets(1)
Dim rowCurrent As Range = ws.Rows(1, Missing.Value)
CType(rowCurrent.Cells(1, 1), Range).Value2 = "Name"
CType(rowCurrent.Cells(1, 2), Range).Value2 = "Age"
CType(rowCurrent.Cells(1, 3), Range).Value2 = "Gender"
' brutal (there is probably a better way...)
While (wb.Worksheets.Count > 1)
wb.Worksheets(wb.Worksheets.Count).Delete()
End While
' store the template where templates go.
Dim strAppDataDir As String = Environment.GetEnvironmentVariable("APPDATA")
Dim strTemplateDir As String = strAppDataDir + "\Microsoft\Templates\Templ1.xlt"
wb.SaveAs(strTemplateDir, XlFileFormat.xlTemplate)
' be sure to close the workbook and Quit out of Excel
okay, I have this new Idea, think it'll be better,
I have this stored template in the server, and I think that i'll just import this excel template file in the datatable and then use the datatable for the template of the excel templates, I just don't know how can I use the datatable as my template, can you please help me,
Thanks
jbutardo
Junior Poster in Training
74 posts since Jan 2012
Reputation Points: 8
Solved Threads: 2
Skill Endorsements: 0
Why would you out it in a database?
Why not a file server or ftp server?
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Why would you out it in a database?
Why not a file server or ftp server?
can you advise me on how to use fileserver of ftpserver?
jbutardo
Junior Poster in Training
74 posts since Jan 2012
Reputation Points: 8
Solved Threads: 2
Skill Endorsements: 0
How is this template going to be used by you or the customer?
Will they click on a link and it is delivered to them?
Will they just browse to a file location and get it?
Will they set their templates directory (in Excel) to include these types of templates?
That will dictate where it's best to put it.
thines01
Postaholic
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
How is this template going to be used by you or the customer?
Will they click on a link and it is delivered to them?
Will they just browse to a file location and get it?
Will they set their templates directory (in Excel) to include these types of templates?
That will dictate where it's best to put it.
anyways, I have made a solution for my problem..
using an excel file in my server, i have used the response.write code to use the downloadable template in my server,,
thanks for the post by the way..
jbutardo
Junior Poster in Training
74 posts since Jan 2012
Reputation Points: 8
Solved Threads: 2
Skill Endorsements: 0
Question Answered as of 1 Year Ago by
thines01