1.11M Members

How to create an excel file template via vb.net?

 
0
 

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

 
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
 
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

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

 
0
 

Why would you out it in a database?
Why not a file server or ftp server?

 
0
 

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?

 
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.

 
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.

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..

Question Answered as of 2 Years Ago by thines01
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: