Solved

how to read client side excel (.xls) file

Posted on 2004-08-09
5
3,921 Views
Last Modified: 2010-07-27
I am in need of reading client side excel file.
I understand i ned to upload it but i cannot write ti to a disk.

Therefore I need to rea it on the fly.

Can anyone tell me how to do it.
thanks
0
Comment
Question by:sinha_punit
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 125 total points
ID: 11752538
Have them export the Excel file to a CSV comma seperated value file then use this code.
This will give you an upload stream to read from or save, in your case read:

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
       Inherits="WebApplication2.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
      <HEAD>
            <title>WebForm1</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
            <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
            <meta name="vs_defaultClientScript" content="JavaScript">
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
      </HEAD>
      <body MS_POSITIONING="GridLayout">
            <%
            if page.ispostback=false then
            %>
            <form runat="server" enctype="multipart/form-data" ID="Form1">
                    <input type="file" id="file1" runat="server" NAME="file1"
                            style="Z-INDEX: 103; LEFT: 324px; POSITION: absolute; TOP: 117px">
                            
                  <asp:Button id="btn1" runat="server" text="Upload" onclick="upload"
                            style="Z-INDEX: 104; LEFT: 324px; POSITION: absolute; TOP: 172px" />
            </form>
            <%
            end if
            %>
      </body>
</HTML>

Imports System.IO

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents btn1 As System.Web.UI.WebControls.Button
    Protected WithEvents file1 As System.Web.UI.HtmlControls.HtmlInputFile

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init      
        InitializeComponent()
    End Sub

#End Region
   
    Public Sub Upload(ByVal sender As Object, ByVal e As System.EventArgs)

        'You can do this to save the file to the server if you like
        'file1.PostedFile.SaveAs("MyFile.csv")

        Dim r As New StreamReader(file1.PostedFile.InputStream())
        Dim strBuffer As String = r.ReadToEnd
       
        'DO SOMETHING HERE WITH strBuffer
       
        r.Close()
    End Sub
End Class

After that you will have to parse throught the csv file with something like text.split see here for example usage:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstringclasssplittopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctsplit.asp

Regards,

Aeros

0
 
LVL 1

Author Comment

by:sinha_punit
ID: 11752602
thanks aeros for the fast reply,

but the thing is i cannot ask the users to export to csv,
they will upload xls and i need to read from xls without saving to disk.

thanks
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11752738
well the above code will upload to a stream, and then to a string, I'm just not sure what kind of format the string will be in when you upload a.csv file.  If you start with that code you should at least be able to see what the string is going to look like and then we can go from there.

Regards,

Aeros
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now