Skip to main content
Inspiring
September 28, 2017
Question

Open an Excel template and add an sheet with CF 10

  • September 28, 2017
  • 0 replies
  • 245 views

Hello,

I have a template containing some static pages saved on the server and I would like to add the dynamic pages to create another Excel file.

My problem is to open the template.

I Receive the following error: "The workbook already contains a sheet of this name"

How to do that?

The template name : "Template.xlsm"

My current code:

<cfset srcUploadedFile = application.settings.loadExcelDirectory & sepa & "Template.xlsm">

<!--- I would like to create an object "s" which is my Excel document --->

<cfspreadsheet action="read" src="#srcUploadedFile#" sheetname="History-version" name="s">

<!--- Create a new sheet and fill the new dynamic page --->

<cfset SpreadsheetCreateSheet (s, "Dynamic 1")>

<cfset SpreadsheetSetActiveSheet(s, "Dynamic 1")>

<cfset headerText = "" >

<cfset headerText = ListAppend(headerText, "Title 1") >

<cfset headerText = ListAppend(headerText, "Title 2") >

<cfset SpreadsheetAddRow(s, headerText)>

<!--- Create the new document --->

<cfheader name="content-disposition" value="attachment; filename=NewFile.xlsm">

<cfcontent type="application/msexcel" variable="#spreadsheetReadBinary(s)#" reset="true"> 

<cfabort>

Thank you in advance for your help

Best regards

Andre

    This topic has been closed for replies.