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

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

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

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

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?

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.