473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Writing into Excel file and reading from it

Hi All,

I have written a program to write the data into excel file (for eg: file.xls). This writes the data into the active sheet, ie, the sheet1. However I wish to write and read data from an excel file's second sheet.

The coding should be in ASP.

The code writtenb by me is as follows:
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <%
  3.  
  4. Dim objXl
  5. Set objXl = server.CreateObject("Excel.sheet")
  6. objXl.Application.Visible = True
  7.  Create the yellow face
  8. objXl.ActiveSheet.Cells(1,1).Value = "hi"
  9.  
  10. objXl.SaveAs "c:\file.xls"
  11. objXl.Application.Quit
  12. Set objApp = Nothing 
  13. %>
Please let me know how to input and retrieve data from the cells of second sheet(sheet2) of an excel file.
Regards
Milan joey
Oct 26 '07 #1
4 4765
jhardman
3,406 Expert 2GB
Milan,

I have accessed the second sheet of an excell file by opening the file as a database and referring to the different sheets as different db tables. I know it's a bit of a hack, but it does work. Sorry, that's my best suggestion.

Jared
Oct 26 '07 #2
Jared,
could you share it with me? Could you provide me the sample code to retrieve data from the sheet2 of an excel sheet?

Thank
Please reply ASAP

regards
Milan
Oct 29 '07 #3
Hi All,
To read from the second sheet of an excel file, do the following

Create a "Sample.xls" file. In sheet2, select the range of cells which you wish to populate with data, and then do the following
1. From the menu bar, select Insert-> Name-> Define Name

For eg I have named it as data. then input the data into these columns and rows, then to retrieve data from sheet2 of Sample.xls, please find the code below:
Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <HTML>
  3. <HEAD>
  4. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
  5. </HEAD>
  6. <BODY>
  7. <%
  8.  
  9. dim adoCon,strCon
  10. Set adoCon = Server.CreateObject("ADODB.Connection")
  11. strcon ="DBQ=" & Server.MapPath("sample.xls") & ";" & _
  12. "DRIVER={Microsoft Excel Driver (*.xls)};"
  13.  
  14. adoCon.Open strCon
  15. %>
  16. <%
  17. 'on error resume next
  18. dim rsCustomQuery
  19. dim rsColumnSchema
  20. dim rsTableSChema
  21. dim strSQl
  22. dim i
  23. Const adSchemaTables = 20
  24. const adSchemaColumns = 4
  25. %>
  26. <html>
  27. <head>
  28. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  29. <%
  30. set rsColumnSchema = adocon.OpenSchema(adSchemaColumns)
  31. set rsTableSChema = adocon.OpenSchema(adSchemaTables)
  32.  
  33. 'Intialise the ADO recordset object
  34. Set rsCustomQuery = Server.CreateObject("ADODB.Recordset")
  35. 'Initialise the SQL variable with an SQL statement to get the configuration details from the database
  36. strSQL = "select * from data;"
  37. 'Query the database
  38. rsCustomQuery.Open strSQL, strCon, 1, 3
  39. %>
  40. <p align="center">Your sql statement as executed is: <b><%=strSQL%></b></p>
  41. <div> 
  42.     <table border="1" cellspacing="0">
  43.       <tr>
  44.       <% For i = 0 to rsCustomQuery.Fields.Count - 1 %>
  45.             <TD><B><% = rsCustomQuery(i).Name %></B></TD>
  46.             <% Next %>
  47.       </tr>
  48.       <%
  49.         Do While Not rsCustomQuery.EOF
  50.           %>
  51.       <tr>
  52.             <% For i = 0 to rsCustomQuery.Fields.Count - 1 %>
  53.             <TD VALIGN=TOP><% = rsCustomQuery(i) %></TD>
  54.             <% Next %>
  55.       </tr>
  56.           <%
  57.             rsCustomQuery.MoveNext
  58.             Loop
  59.       %>
  60.   </table>
  61. </div>
  62. <%=request.Form("sel") %>
  63.  
  64. </BODY>
  65. </HTML>
  66.  
Please let me know if anybody has tried to insert data into the Second sheet of the excel file. Could you help me with the same?
I need to extract data from Sql server and populate a particular column in the excel file's sheet2.

If any body has already come up with a solution, in ASP, please share it with me.

Thanks n Regards
Milan
Oct 30 '07 #4
jhardman
3,406 Expert 2GB
Please let me know if anybody has tried to insert data into the Second sheet of the excel file. Could you help me with the same?
I need to extract data from Sql server and populate a particular column in the excel file's sheet2.

If any body has already come up with a solution, in ASP, please share it with me.

Thanks n Regards
Milan
Milan,

Your solution so far looks better than mine. Tell me, how is your second sheet organized? Is it something that a db driver could interpret? If not, my method won't work.

Jared
Nov 2 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
10
by: Aaron | last post by:
Hello, I have a small application that I need to save data from 7 text boxes in to a csv file. This will entail btnNext_Click function that will create a new csv file and enter the 7 data fields...
3
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
2
by: arvind1083 | last post by:
I need help for writing a excel file. As in one excel file there could be more than one sheets so I want to know how can I give name to different sheets and select a particular sheet for writing or...
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
1
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file...
8
by: fahadqureshi | last post by:
Hello, I posted here before asking a question about reading excel. Now that the reading problem is solved i am having trouble on how to write to an excel file. This was my code to read the excel...
1
by: =?Utf-8?B?ZmhpbGxpcG8=?= | last post by:
We have a code snippet that downloads data to Excel. it is writing row by row. This causes a performance issue. Any ideas on how to speed this up will be appreciated. Please find below an...
20
by: Marin Brkic | last post by:
Hello all, please, let me apologize in advance. English is not my first language (not even my second one), so excuse any errors with which I'm about to embarass myself in front of the general...
12
by: vijayarl | last post by:
Hi All, To Moderator : Sorry i have posted this querry to member rather putting in the forum. To All: Problem stmt: I am reading the data from the excel files & writing its content to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.