Solved

how to read client side excel (.xls) file

Posted on 2004-08-09
5
3,925 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Code works but how can I download the file? 20 67
ISS migration from IIS 6 to IIS 8.5 rendering problems 4 52
Achieve json result 2 65
ASP.NET Web API or ASP.NET Core MVC? 3 53
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

862 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

23 Experts available now in Live!

Get 1:1 Help Now