Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 10th, 2005, 01:37 AM
Authorized User
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dotnetprogrammer
Default Exporting listview data to excel file

Hi!

I am using the following code to create a excel file. I have office 2003 installed in my machine. I have made following reference Microsoft excel 11.0 object library. The code is working fine in my machine. But in other machine (where office 2000 is installed) It is giving object reference not set to instance of object exception in the following line.

oWB.SaveAs(strfilename ,Ex.XlFileFormat.xlWorkbookNormal, null, null,false,
false, Ex.XlSaveAsAccessMode.xlShared, false, false, null,
null, null);


using Ex=Microsoft.Office.Interop.Excel;


Ex.Application oXL;
Ex._Workbook oWB;
Ex._Worksheet oSheet;
oXL = new Ex.Application();

oXL.Visible = false;
oWB= (Ex._Workbook)(oXL.Workbooks.Add( Missing.Value ));
oSheet = (Ex._Worksheet)oWB.ActiveSheet;
//oSheet.Columns
oSheet.Cells[1,1]="A";
oSheet.Cells[1,2]="B";
oSheet.Cells[1,3]="C";
oSheet.Cells[1,4]="D";
oSheet.Cells[1,5]="E";
oSheet.Cells[1,6]="F";
((Ex.Range)oSheet.Cells[1,1]).ColumnWidth = 20;
((Ex.Range)oSheet.Cells[1,2]).ColumnWidth = 20;
((Ex.Range)oSheet.Cells[1,3]).ColumnWidth = 20;
((Ex.Range)oSheet.Cells[1,4]).ColumnWidth = 40;
((Ex.Range)oSheet.Cells[1,5]).ColumnWidth = 20;
((Ex.Range)oSheet.Cells[1,6]).ColumnWidth = 20;
((Ex.Range)oSheet.Cells[1,1]).EntireRow.Font.Bold = true;
for(int i=0 ; i<FsciListView.Items.Count ; i++)
{
for(int j=1; j<=6 ; j++)
{
string str = listView1.Items[i].SubItems[j].Text;
oSheet.Cells[i+2,j] = str;
}
}
string strfilename = "C:\\tmp\\test.xls";
oWB.SaveAs(strfilename ,Ex.XlFileFormat.xlWorkbookNormal, null, null,false,
false, Ex.XlSaveAsAccessMode.xlShared, false, false, null,
null, null);
// Below line will kill the unkilled Excel process
System.Diagnostics.Process[] pProcess;
pProcess = System.Diagnostics.Process.GetProcessesByName("Exc el");
pProcess[0].Kill();
oSheet= null;
oWB = null;
oXL = null;


Please help me
I am really stuck in this

Regards
Saurabh

dotnet
__________________
dotnet
Reply With Quote
  #2 (permalink)  
Old May 10th, 2005, 02:15 AM
Friend of Wrox
 
Join Date: Apr 2005
Location: Cochin, , India.
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

There is chance of changes in api of excel 2000 & 2003 so you may have to create the introp file for 2000 which may be compatible for 2003, but in usualy backward compatiblity may not be there for some api.

Another thing,Do you have tmp folder in that machine also?

Prashant

Reply With Quote
  #3 (permalink)  
Old May 10th, 2005, 08:13 AM
Authorized User
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dotnetprogrammer
Default

Yes I have tmp folder in that machine also.
Could you plz give me some code that will work in every version of outlook.

Regards

Saurabh

dotnet
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data to Excel lrickett Beginning VB 6 3 February 10th, 2011 12:27 AM
Exporting data from datagrid to excel??? twyce C# 3 March 4th, 2010 03:51 AM
help exporting data to excel MarkGT Classic ASP Basics 5 April 29th, 2008 06:13 PM
Exporting data into Excel file from SSIS atulmar Reporting Services 0 November 21st, 2006 08:35 AM
Exporting data to excel sheet x_ray VB.NET 2002/2003 Basics 0 January 6th, 2006 02:14 PM



All times are GMT -4. The time now is 05:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.