• Giangdt
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

I have a vbscript code inside my VF page,

which reads an excel file and displays the content

in a textarea.

 

Its not working at all. ie if you click the Read button

nothing happens.

 

Does VF pages support vbscript code?

 

Here is my code

 

<apex:page showHeader="false">
<apex:messages />

<script type="text/vbscript">

Sub readBtn_OnClick

Dim fileUrl
Dim rowIndex
Dim colIndex
Dim oldContent
Dim newContent
Dim cellContent

fileUrl = document.form.userFile.value
Set objExcel = CreateObject("Excel.Application")
MsgBox "Excel Obj Created"
Set objWorkbook = objExcel.Workbooks.Open(fileUrl)
MsgBox "Excel Workbook Created"

rowIndex = 1
colIndex = 1
Do Until objExcel.Cells(rowIndex ,colIndex).Value = ""
oldContent = document.form.excelContent.value
newContent = oldContent & objExcel.Cells(rowIndex , colIndex).Value & vbCr & vbLf
document.form.excelContent.value = newContent
rowIndex = rowIndex + 1
Loop
objExcel.Workbooks(1).Close
objExcel.Quit
End Sub

</script>

<form name="form">
<input type="file" name="userFile"/>
<input type="button" value="Read" name="readBtn"/>
<p><textarea rows="10" cols="44" name="excelContent"></textarea></p>
</form>

</apex:page>

 

 

I have a requirement where through VF page, user will upload an Excel file.

Controller has to read this excel file and display the values in the same page.

 

Now my question would be

 

1. Is it possible to read the excel content in controller class?

2. If it is possible, can you explain me with some sample code?