Click here to Skip to main content
15,891,607 members
Home / Discussions / C#
   

C#

 
GeneralRe: ISS algorithm Implementation Pin
Dave Kreskowiak30-Nov-06 12:30
mveDave Kreskowiak30-Nov-06 12:30 
QuestionTell Explorer to Reload Display Registry Settings? Pin
nrafalski29-Nov-06 11:30
nrafalski29-Nov-06 11:30 
QuestionProcess.Start (Java) Pin
amatbrewer29-Nov-06 10:55
amatbrewer29-Nov-06 10:55 
AnswerRe: Process.Start (Java) Pin
Judah Gabriel Himango29-Nov-06 16:24
sponsorJudah Gabriel Himango29-Nov-06 16:24 
Questionread vs readline in c#.net Pin
saravanan0529-Nov-06 10:42
saravanan0529-Nov-06 10:42 
AnswerRe: read vs readline in c#.net Pin
Eric Dahlvang29-Nov-06 10:59
Eric Dahlvang29-Nov-06 10:59 
QuestionMicrosoft.Office.Interop.Excel Pin
spinz211229-Nov-06 10:41
spinz211229-Nov-06 10:41 
AnswerRe: Microsoft.Office.Interop.Excel Pin
Torsten Mauz29-Nov-06 11:33
Torsten Mauz29-Nov-06 11:33 
Your using statement will be
using Microsoft.Office.Core;


Just because I've been through this pain before and the documentation for automatation is awful, I thought I'd paste an old demo I had lying around...
private void ReadExcelValue()
{
    object o = System.Reflection.Missing.Value;
 
    Excel.Application objE = new Excel.Application();
    Excel.Workbooks objBooks = null;
    Excel.Workbook objB = null;
    Excel.Worksheet objS = null;
 
    objE.Workbooks.Open(Server.MapPath("spreadsheet.xls"), o, o, o, o, o, o, o, o, o, o, o, o, o, o);
    objBooks = objE.Workbooks;
    objB = objBooks[(object)1];
 
    objS = (Excel.Worksheet)objB.Worksheets[(object)1];
 
    //write out the text in cell "A1"
    Response.Write(((Excel.Range)objS.Cells[1, 1]).Text);
 
    Release(objS);
 
    if (objB != null)
        objB.Close(false, o, o);
    Release(objB);
 
    if (objBooks != null)
        objBooks.Close();
    Release(objBooks);
 
    if (objE != null)
        objE.Quit();
    Release(objE);
 
    GC.Collect();
 
    System.Diagnostics.Process[] objPr = System.Diagnostics.Process.GetProcessesByName("Excel");
    foreach (System.Diagnostics.Process pr in objPr)
        pr.Kill();
}

private void Release(object obj)
{
    try
    {
        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
    }
    catch { }
    finally
    {
        obj = null;
    }
}


Note: It's rather ugly stuff and there's a cheesy hack to make sure that the excel process doesn't persist on the server after execution (yes it's pretty easy to end up with thousands of Excel.exe processes if you don't kill them).

HTH
GeneralRe: Microsoft.Office.Interop.Excel Pin
spinz211229-Nov-06 20:03
spinz211229-Nov-06 20:03 
GeneralRe: Microsoft.Office.Interop.Excel Pin
Torsten Mauz30-Nov-06 1:16
Torsten Mauz30-Nov-06 1:16 
GeneralRe: Microsoft.Office.Interop.Excel Pin
spinz211230-Nov-06 8:34
spinz211230-Nov-06 8:34 
GeneralRe: Microsoft.Office.Interop.Excel Pin
Drew McGhie30-Nov-06 8:38
Drew McGhie30-Nov-06 8:38 
GeneralRe: Microsoft.Office.Interop.Excel Pin
spinz211230-Nov-06 9:30
spinz211230-Nov-06 9:30 
GeneralRe: Microsoft.Office.Interop.Excel Pin
Drew McGhie30-Nov-06 10:59
Drew McGhie30-Nov-06 10:59 
QuestionUser Control Resize not Obeying Anchors? Pin
cduced29-Nov-06 10:14
cduced29-Nov-06 10:14 
AnswerRe: User Control Resize not Obeying Anchors? Pin
cduced1-Dec-06 11:25
cduced1-Dec-06 11:25 
QuestionRichTextBox - Saving embedded controls Pin
Anthony Queen29-Nov-06 9:32
Anthony Queen29-Nov-06 9:32 
GeneralRe: RichTextBox - Saving embedded controls [modified] Pin
Anthony Queen29-Nov-06 9:37
Anthony Queen29-Nov-06 9:37 
GeneralRe: RichTextBox - Saving embedded controls Pin
mav.northwind29-Nov-06 18:59
mav.northwind29-Nov-06 18:59 
GeneralRe: RichTextBox - Saving embedded controls Pin
Anthony Queen30-Nov-06 3:57
Anthony Queen30-Nov-06 3:57 
GeneralRe: RichTextBox - Saving embedded controls Pin
Anthony Queen4-Dec-06 3:00
Anthony Queen4-Dec-06 3:00 
QuestionListbox and contextmenu Pin
iakob29-Nov-06 9:05
iakob29-Nov-06 9:05 
AnswerRe: Listbox and contextmenu Pin
led mike29-Nov-06 9:14
led mike29-Nov-06 9:14 
AnswerRe: Listbox and contextmenu Pin
Scott Dorman29-Nov-06 10:57
professionalScott Dorman29-Nov-06 10:57 
AnswerThanks Was: Listbox and contextmenu Pin
iakob29-Nov-06 20:34
iakob29-Nov-06 20:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.