473,383 Members | 1,859 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,383 software developers and data experts.

Opening an excel sheet with .net

19
the code which i hav already throws some error wen i debug
here is my code
plz reply me as soon as possible

Private Sub Page_Load(ByVal sender As _

System.Object, ByVal e As System.EventArgs) _

Handles MyBase.Load

Dim dt As DataTable = _

CType(Application.Item("MyDataTable"), DataTable)



Response.ContentType = "application/ms-excel"



Response.AddHeader("Content-Disposition", _

"inline;filename=test.xls")



Response.Write(ConvertDtToTDF(dt))

End Sub



'Converts a DataTable to Tab Delimited Format

Private Function ConvertDtToTDF(ByVal _

dt As DataTable) As String

Dim dr As DataRow, ary() As Object, i As Integer

Dim iCol As Integer



'Output Column Headers

For iCol = 0 To dt.Columns.Count - 1

Response.Write(dt.Columns(iCol).ToString & vbTab)

Next

Response.Write(vbCrLf)



'Output Data

For Each dr In dt.Rows

ary = dr.ItemArray

For i = 0 To UBound(ary)

Response.Write(ary(i).ToString & vbTab)

Next

Response.Write(vbCrLf)

Next

End Function
Jan 25 '07 #1
7 1080
radcaesar
759 Expert 512MB
Whats the exception u got and where ?

:)
Jan 25 '07 #2
derik
19
Whats the exception u got and where ?

:)
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

For iCol = 0 To dt.Columns.Count - 1
Jan 25 '07 #3
radcaesar
759 Expert 512MB
This is because the datatable dt has null reference (Not declared correctly) or the method dt.Columns.Count - 1 has returning NULL.

Check out.

:)
Jan 25 '07 #4
derik
19
This is because the datatable dt has null reference (Not declared correctly) or the method dt.Columns.Count - 1 has returning NULL.

Check out.

:)
ya but stilll its not working ... wat can i put instead

can u suggest me any alternative
Jan 25 '07 #5
radcaesar
759 Expert 512MB
Check what ur dt.columncount - 1 had return there.

Else

Comment that for loop and try.

:)
Jan 25 '07 #6
misogsk
39
You can also try to use a OleDB connection to your excel file.

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Book1.xls;Extended Properties= ""Excel 8.0;HDR=YES;""";

Now you can create dataadater and command.
Command.text should for example SELECT col1,col2 FROM [sheet$]
This fill your dataadapter and then use dataadapter method fill to fill a new dataset
adapter_name.Fill(dataset_name);
Assign dataset to Datasource property of your control.
I hope this helps you.
Jan 25 '07 #7
derik
19
Check what ur dt.columncount - 1 had return there.

Else

Comment that for loop and try.

:)
tanx for ur reply...

making dat loop as comment is not workink out..
Jan 25 '07 #8

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

Similar topics

1
by: Jawahar Rajan | last post by:
All, I am using the ASP code below to save some data from a SQL Server database via ADO as an Excel spreadsheet strReportName = Request.QueryString("ReportName") If len(strReportName) > 0 then...
2
by: matt | last post by:
(apologies for the cross-post.. im not normally in the habit of such things) SHORT VERSION (for smart people in a hurry): I need some way to programmatically cause the update of calculated...
3
by: | last post by:
I wrote a class in VB.NET to export the contents of a datagrid to Excel. It works perfectly on my machine, but it fails on my customers' PCs that have identical versions of Win XP (SP1) and Excel...
1
by: Boomessh | last post by:
Hi, I am trying to open an existing excel workbook. It pops up an error stating that “Errors were detected in 1598.xls but Microsoft Office Excel was able to open the file by making the repairs...
8
by: Djim | last post by:
Hello, i am starting PHP, and after 2 days of search, i am posting. MY PURPOSE : opening a XLS files (in MS Excel) on the client side, the user can update anything, then it will be automaticly...
3
by: implicate_order | last post by:
Greetings, I'm new to python and am in the process of writing a script to parse some CSV data, spread it across multiple Excel worksheets and then generate charts. I searched the internet to...
0
by: sandeep ch | last post by:
hi , I am opening a excel sheet from perl but every time i run the program i get a pop up message saying that "This Workbook contains links to other sources" " - To update all linked information...
0
by: manontheedge | last post by:
I have a program in VB6 that gets data from an internet site, puts it in excel, then opens that excel sheet. It works, but only because I'm throwing an exception and ignoring the error that keeps...
1
by: gowthamkumar | last post by:
HII ... please give me a code to open a new excel sheet using VB so that i can also directly add some contents in the cells of the excel sheet in VB itself .. i ve use the existing excel sheet code...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
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
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.