?
Solved

how to read client side excel (.xls) file

Posted on 2004-08-09
5
Medium Priority
?
3,953 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

777 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