Solved

how to read client side excel (.xls) file

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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