Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 1.0 and Visual Studio.NET > VS.NET 2002/2003
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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
 
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

 
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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Exporting data to Excel lrickett Beginning VB 6 3 February 10th, 2011 01:27 AM
Exporting data from datagrid to excel??? twyce C# 3 March 4th, 2010 04: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 09:35 AM
Exporting data to excel sheet x_ray VB.NET 2002/2003 Basics 0 January 6th, 2006 03:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.