Shantanu Sen

Dear all

I have a project which fetch data from HTML web page and writes it into a excel sheet .

I have office 2000 installed on my PC which uses Microsoft Excel 9.0 Object Library

right now i am able to write the data in a excel sheet , but i am not able to format the sheet for some unwanted entry using the library.

Please provide some resolution

shantanu




Re: Visual Studio Tools for Office Format excel sheet using c#

senthildekumar

If possible please post the code here which might be helpful in identifying the problem..





Re: Visual Studio Tools for Office Format excel sheet using c#

Shantanu Sen

In the reference i have added Excel 9.0 library.

I am getting a error "Additional information: QueryInterface for interface Excel._Application failed."

The Below given code is the whole implementation

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

namespace ExcelManip

{

/// <summary>

/// Summary description for Form1.

/// </summary>

public class Form1 : System.Windows.Forms.Form

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

private Excel.Application _app;

private Excel.Workbooks _books;

private Excel.Workbook _book;

protected Excel.Sheets _sheets;

private System.Windows.Forms.Button button1;

protected Excel.Worksheet _sheet;

public Form1()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.button1 = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(104, 88);

this.button1.Name = "button1";

this.button1.TabIndex = 0;

this.button1.Text = "button1";

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(292, 266);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

protected void OpenExcelWorkSheet(string fileName)

{

_app = new Excel.Application();

if (_book==null)

{

_books = _app.Workbooks;

_book = _books.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

_sheets = _book.Worksheets;

}

}

protected void CloseExcelWorkbook()

{

_book.Save();

_book.Close(false, Type.Missing, Type.Missing);

}

protected void NAR(object o)

{

try

{

if(o != null)

System.Runtime.InteropServices.Marshal.ReleaseComObject(o);

}

finally

{

o = null;

}

}

private void button1_Click(object sender, System.EventArgs e)

{

//OpenExcelWorkbook(@"d:\temp\yourworkbook.xls");

OpenExcelWorkSheet(@"d:\temp\MSFT.xls");

_sheet = (Excel.Worksheet)_sheets[1];

_sheet.Select(Type.Missing);

Excel.Range range = _sheet.get_Range("A7:A7", Type.Missing);

range.Delete(Excel.XlDeleteShiftDirection.xlShiftUp);

NAR(range);

NAR(_sheet);

CloseExcelWorkbook();

NAR(_book);

_app.Quit();

NAR(_app);

}

}

}






Re: Visual Studio Tools for Office Format excel sheet using c#

Andrew Whitechapel - MSFT

This question does not involve VSTO. It is a question purely on the Excel object model. Please repost your question to a more appropriate forum, such as the Excel programming forum:

http://msdn.microsoft.com/newsgroups/default.aspx dg=microsoft.public.excel.programming&lang=en&cr=US