Updating existing Excel sheet in C#

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
I am wanting to update an existing sheet called Electronic Input in a workbook. It happens to be the first sheet, but Im not sure this will always be the case. I am getting some unpredictable results. I am issing a Get_item for the sheet,
but I would rather specify the sheet name. How can I do that? Here is my current code
<span style="font-size:x-small <font size="2
oXL =
</font>
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small Excel.<span style="color:#2b91af; font-size:x-small <span style="color:#2b91af; font-size:x-small Application<span style="font-size:x-small ();<font size="2

oXL.Visible =
</font>

<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<span style="font-size:x-small ;<font size="2

oXL =
</font>

<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small new<span style="font-size:x-small Excel.<span style="color:#2b91af; font-size:x-small <span style="color:#2b91af; font-size:x-small ApplicationClass<span style="font-size:x-small ();<font size="2

oWB = oXL.Workbooks.Open(fileToLoad, 0,
</font>

<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small false<span style="font-size:x-small , 5,
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small ""<span style="font-size:x-small ,
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small ""<span style="font-size:x-small ,
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<span style="font-size:x-small , Microsoft.Office.Interop.Excel.<span style="color:#2b91af; font-size:x-small <span style="color:#2b91af; font-size:x-small XlPlatform<span style="font-size:x-small .xlWindows,
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small "t"<span style="font-size:x-small ,
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small false<span style="font-size:x-small ,
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small false<span style="font-size:x-small , 0,
<span style="color:#0000ff; font-size:x-small <span style="color:#0000ff; font-size:x-small true<span style="font-size:x-small , 1, 0);<font size="2

oSheet = (Excel.
</font>

<span style="color:#2b91af; font-size:x-small <span style="color:#2b91af; font-size:x-small Worksheet<span style="font-size:x-small )oWB.Worksheets.get_Item(1);
<span style="font-size:x-small <span style="font-size:x-small <font size="2
oSheet.Cells[1, 1] =
</font>
<span style="color:#a31515; font-size:x-small <span style="color:#a31515; font-size:x-small "Car Type"<span style="font-size:x-small ;<span style="font-size:x-small

oSheet.Cells[lineNumber, 1] = tcarType;




View the full article
 
Back
Top