Click here to Skip to main content
15,896,118 members
Home / Discussions / C#
   

C#

 
GeneralRe: com add in excel2010 Pin
PozzaVecia11-Feb-12 5:31
PozzaVecia11-Feb-12 5:31 
GeneralRe: com add in excel2010 Pin
Abhinav S11-Feb-12 17:04
Abhinav S11-Feb-12 17:04 
GeneralRe: com add in excel2010 Pin
PozzaVecia11-Feb-12 6:09
PozzaVecia11-Feb-12 6:09 
Questionocr from japenese to english using c# with MODI Pin
udayakumard10-Feb-12 23:21
udayakumard10-Feb-12 23:21 
AnswerRe: ocr from japenese to english using c# with MODI Pin
Dave Kreskowiak11-Feb-12 2:08
mveDave Kreskowiak11-Feb-12 2:08 
QuestionAccess is denied Pin
jon-8010-Feb-12 22:29
professionaljon-8010-Feb-12 22:29 
AnswerRe: Access is denied Pin
fjdiewornncalwe11-Feb-12 5:40
professionalfjdiewornncalwe11-Feb-12 5:40 
QuestionWriting to an excel file Pin
JFRobertson10-Feb-12 20:12
JFRobertson10-Feb-12 20:12 
I am new to working with com objects and trying to figure out how to make this work. The code runs and it hits the if statement and even writes out the test message in the if statement. The problem is that when I open the excel file there is no change. It did somehow corrupt one and tell me that it is read only now and it will occasionally pop up the do you want to save this excel file message, but nothing ever shows. I have also tried Value and Value2 as I have seen in various pages, but I just can't find anything that does what I want it to do or any place that even gives good help on how to do it. This is the code I am using. A lot of it is just hardcoded test values so it really should be straight forward.
var excelDocument = new Excel.Application();
Excel.Workbook xlWorkbook = excelDocument.Workbooks.Open(@"c:/score/W5490C - Fresh.xlsx");
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;

//Calculate and record the air losses.
int totalAircraftLostAA = 0;
int totalAircraftLostSA = 0;
ScoreCalculations.CalculateEnemyAirLosses(events, ref totalAircraftLostAA, ref totalAircraftLostSA);
int column = 3;
for (int row = 1; row <= rowCount; row++)
{
if (xlRange.Cells[row, 1].Value2.ToString() == "Aircraft Kills (A-A)")
{
Console.WriteLine(xlWorkbook.Sheets[1]);
Console.WriteLine("write attempted");
xlRange.Cells[row, column].Value2 = totalAircraftLostAA;
}
}


//Calculate and record ally airlosses
ScoreCalculations.CalculateAllyAirLosses(events);

//Calculate and record expended Ordnance
ScoreCalculations.CalculateExpendedOrdnance(events);

//Calculate and record ground targets hit
ScoreCalculations.CalculateNamedGroundTargets(events);

xlWorkbook.Save();
xlWorkbook.Close();

Thanks to anyone that can see what is probably the dumb mistake that I am making.

Jimmy
AnswerRe: Writing to an excel file Pin
Richard MacCutchan10-Feb-12 23:48
mveRichard MacCutchan10-Feb-12 23:48 
GeneralRe: Writing to an excel file Pin
JFRobertson11-Feb-12 8:08
JFRobertson11-Feb-12 8:08 
GeneralRe: Writing to an excel file Pin
Richard MacCutchan11-Feb-12 23:32
mveRichard MacCutchan11-Feb-12 23:32 
GeneralRe: Writing to an excel file Pin
Richard MacCutchan12-Feb-12 1:13
mveRichard MacCutchan12-Feb-12 1:13 
GeneralRe: Writing to an excel file Pin
JFRobertson12-Feb-12 8:49
JFRobertson12-Feb-12 8:49 
QuestionRe: Writing to an excel file Pin
Richard MacCutchan12-Feb-12 9:07
mveRichard MacCutchan12-Feb-12 9:07 
GeneralRe: Writing to an excel file Pin
BobJanova12-Feb-12 22:44
BobJanova12-Feb-12 22:44 
GeneralRe: Writing to an excel file Pin
Richard MacCutchan12-Feb-12 23:02
mveRichard MacCutchan12-Feb-12 23:02 
QuestionWhy IsBetweenLabels property only works for AxysType Text? Pin
Thiago Marçal10-Feb-12 8:04
Thiago Marçal10-Feb-12 8:04 
QuestionText Editor Pin
jeramyRR10-Feb-12 6:41
jeramyRR10-Feb-12 6:41 
AnswerRe: Text Editor Pin
Eddy Vluggen10-Feb-12 6:52
professionalEddy Vluggen10-Feb-12 6:52 
GeneralRe: Text Editor Pin
jeramyRR10-Feb-12 7:15
jeramyRR10-Feb-12 7:15 
QuestionGenerating html tree from xml file using XSLT..? Pin
anikbutt2210-Feb-12 6:16
anikbutt2210-Feb-12 6:16 
AnswerRe: Generating html tree from xml file using XSLT..? Pin
jschell10-Feb-12 9:24
jschell10-Feb-12 9:24 
GeneralRe: Generating html tree from xml file using XSLT..? Pin
anikbutt2210-Feb-12 14:18
anikbutt2210-Feb-12 14:18 
GeneralRe: Generating html tree from xml file using XSLT..? Pin
jschell12-Feb-12 7:31
jschell12-Feb-12 7:31 
Questionc# code to convert txt to xls Pin
taurusone10-Feb-12 4:37
taurusone10-Feb-12 4:37 

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.