Problem downloading an edited excel file

I am unsure whether its a mental block or what but everything seems to work fine as far as I can tell but the webfile cannot be found to download so I am suspecting my paths may be mixed up somewhere. I have an excel template workbook sat against my webapp.

I copy the template file to a new file which is then edited, all works great using libxl, and the new file is saved in the right place but I cannot seem to ‘grab it’ to download. I have not yet uploaded to server, this is all being done in debug mode (does that make a difference?).

Anyone with any clues as to what I am doing wrong?

What I want to do is this;

Copy excel template file (sat in same dir as webapp)
Edit the copy and insert some values
Save the copy
Download the copy
Check its downloaded (yet to be added)
Delete the copy (yet to be added)

dim d as new date
dim dnload as new webfile

app.RegisterLibXL

// create new xls file
dim book as new XLBookMBS(false)
dim file, tempfile as FolderItem

// load existing template
#if DebugBuild then
  file  = getfolderitem("../rtime.xls")
  tempfile=getfolderitem("../"+cstr(session.forceID)+"_rtime-"+d.SQLDate+".xls")
  file.CopyFileTo(tempfile)
  file = tempfile
#else
  file  = getfolderitem("rtime.xls")
  tempfile=new folderitem(cstr(session.forceID)+"_rtime-"+d.SQLDate+".xls")
  file.CopyFileTo(tempfile)
  file = tempfile
#endif


if file.Exists = false then
  MsgBox "Please run Format project first."
  quit
end if

if not book.Load(file) then
  MsgBox "Failed to read file: "+book.ErrorMessage
  quit
end if

'MsgBox str(book.SheetCount)+" sheets"

// do some changes
dim sheet as XLSheetMBS = book.Sheet(0)
if sheet<>Nil then
  
  // and some text
  call sheet.WriteString 1, 0, "A and S"
  
  // read number
  call sheet.WriteNumber 5, 1, 5
  call sheet.WriteNumber 6, 1, 6
  call sheet.WriteNumber 7, 1, 7
  call sheet.WriteNumber 8, 1, 8
  call sheet.WriteNumber 9, 1, 9
  call sheet.WriteNumber 10, 1, 10
  
end if

// write file

if book.Save(file) then
  
  //not sure if this mime type required but seems reasonable
  dnload.MimeType = "application/vnd.ms-excel"
  
  dnload.ForceDownload = True
  dnload = WebFile.Open(file) 
  
  ShowURL(dnload.URL)
  
else
  MsgBox "Failed to create file."+EndOfLine+EndOfLine+book.ErrorMessage
end if

I re-read the post having posted it and saw the problem problem straight away.

dnload is a webfile and a property of the page, the problem was that at line 2,

dim dnload as new webfile

should actually be

dnload = new webfile

The file does not need ‘Dim’

Sorry to disturb you :slight_smile: