|
I just copied your code and ran a test on this and it works fine, although I obviously could not use the ScoreCalculations methods, so I just plugged in some fixed values. As I said in my previous message, you probably need to use your debugger to find out what is going wrong.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Actually it was working. I thought I had verified that there were no hidden sheets, but I forgot to select them all before I clicked unhide. I am having an additional problem now. The code is working, but I have started to encapsulate it so I can make it better as well as start the process of finding which sheet rather than hardcoding, but it is crashing with a can not bind to a null object whether I call save or not. The big problem is that it is actually working even though it is giving the can't bind to a null object at runtime. Thank you for the help. I really hate that I spent so many years avoiding learning com interop, because now that I need it on a deadline it is killing me.
This is how I have modified the code. The calls are pretty much still the same just encapsulated but I am still hardcoding them.
Excel.Application excelDocument = ExcelOperations.GetApplication();
Excel.Workbook xlWorkbook = ExcelOperations.GetWorkbook(excelDocument);
Excel.Worksheet xlWorksheet = ExcelOperations.GetWorksheet("", xlWorkbook);
Excel.Range xlRange = ExcelOperations.GetRange(xlWorksheet);
try
{
var query = QueryTabDocument(columnsCount, filePath);
List<ScoreTabFile> events = query.ToList();
int rowCount = xlRange.Rows.Count;
int colCount = xlRange.Columns.Count;
int totalAircraftLostAA = 0;
int totalAircraftLostSA = 0;
ScoreCalculations.CalculateEnemyAirLosses(events, ref totalAircraftLostAA, ref totalAircraftLostSA);
int column = 3;
for (int row = 1; row <= rowCount; row++)
{
if (string.Equals(xlRange.Cells[row, 1].Value2.ToString(), "Aircraft Kills (A-A)"))
{
Console.WriteLine(xlRange.Cells[row, 1].Value2.ToString());
Console.WriteLine("write attempted");
xlRange.Cells[row, column].Value2 = totalAircraftLostAA;
}
}
ScoreCalculations.CalculateAllyAirLosses(events);
ScoreCalculations.CalculateExpendedOrdnance(events);
ScoreCalculations.CalculateNamedGroundTargets(events);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.FinalReleaseComObject(xlRange);
Marshal.FinalReleaseComObject(xlWorksheet);
xlWorkbook.Close();
Marshal.FinalReleaseComObject(xlWorkbook);
excelDocument.Quit();
Marshal.FinalReleaseComObject(excelDocument);
}
modified 12-Feb-12 16:15pm.
|
|
|
|
|
I'm afraid there's quite a bit in the above that's outside of my experience, so let's hope someone else comes by and offers some suggestions.
BTW it would help if you put your code between <pre> tags (use the code button above) to make it more readable; you can edit your messages to fix it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Yes you can, the equality operators are overloaded to do value matching on strings in C#.
|
|
|
|
|
You learn something new every day.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Greetings.
I need to make a bar graphic divided by months. But the Axis' Type I'm using is DateAsOrdinal (instead of Text) and I need the bars to be inner the tics.
I read in zedgraph documentation that IsBetweenLabels only works with AxisType.Text.
GraphPane painel = masterPane[0];
PointPairList pointPairList = MyDataSource.getList();
BarItem barra = painel.AddBar(listastring, pointPairList, coresbarra[i]);
painel.XAxis.Type = AxisType.DateAsOrdinal;
painel.XAxis.MajorTic.IsBetweenLabels = true;
How can I resolve this? Thank you for your attention.
|
|
|
|
|
Hi all,
I'm fairly new at programming, having taken a few classes in college over the last semster. One thing I'm interested in doing is programming my own HTML editor or JavaScript editor.
I have absolutely no clue where to even begin. All my courses have taught the basics of programming by sending our output to a console window. I just purchased a C# book, and am waiting on it to arrive from Amazon.
My question (I know it took long enough to get to it) is if anyone can point me to any tutorials on how to create a standard text editor that can parse input and change the colors of the text like html editors and ide's do.
Thanks,
Jeramy
|
|
|
|
|
jeramyRR wrote: My question (I know it took long enough to get to it) is if anyone can point me to any tutorials on how to create a standard text editor that can parse input and change the colors of the text like html editors and ide's do.
May I suggest small steps? Like creating a text-editor[^] first, and then learn how to integrate a loading-routine with a parser? Or do you want to dive in directly[^]?
Bastard Programmer from Hell
|
|
|
|
|
No. No. Small steps first, most definitely. I want to learn the right way.
|
|
|
|
|
hey everyone plz help me.. i want to generate the html tree from xml file using XSLT ? is it possible ?
.. kindly reply.. regards..
modified 10-Feb-12 12:31pm.
|
|
|
|
|
Googling the following terms turned up 100,000+ hits. First synopsis of that list seemed relevant to me.
"html tree" xslt
|
|
|
|
|
hy.. no it didnt work for me..i need collapse and expand all functionality in the tree..but this code didnt work.anyways thanks
|
|
|
|
|
To be clear....
Xslt creates the html. The html, not the xslt, is responsible for the any behavior that you see. So the solution there is to first figure out what you need the html to do and then write the xslt to do it.
|
|
|
|
|
Hi
how can i convert the following txt file to xls file. perticular data in txt should be stored on pertular xls cell.
sample txt file:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
This sample txt data (each "txt") should be stored in perticular xls cell.
can anyone give me a C# code which does this.
|
|
|
|
|
if you replace the spaces by comma's, you end up with comma separated values, and CSV files now that is something Excel likes a lot.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
did not completly understand your word. can u give me any sample code to convert:
txt to xls
OR
txt to CSV to xls
accually data goes like this:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
the above is a variable row, so that set of row should be stored on perticular cell on xls. then the next set of rows should be stored on next perticular set of cells.
|
|
|
|
|
if a simple CSV import doesn't do what you want, then you will need to use the Office Primary Interop Assemblies[^]. I trust CodeProject holds some example articles on the subject. I've never used it myself.
Luc Pattyn [My Articles] Nil Volentibus Arduum
Fed up by FireFox memory leaks I switched to Opera and now CP doesn't perform its paste magic, so links will not be offered. Sorry.
|
|
|
|
|
taurusone wrote: can anyone give me a C# code which does this.
This is a site for programmers - not a restaurant where you can order stuff.
Create a CSV file, open it in Excel. You'll see that it simply opens the CSV file, and treats it whether it was a regular Excel-file. That means that you can concatenate all your files into a single string, separated by comma's, and write it to a CSV.
Bastard Programmer from Hell
|
|
|
|
|
yes i know it is not restaurant and i am not ordering, it a request.
input file:
table 1:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
table 2:
txt1 txt2 txt3 txt4
txt5 txt6 txt7 txt8
txt4 txt3 txt2 txt1
txt4 txt3 txt2 txt1
txt4 txt3 txt2 txt1
note that the table rows or variging. i want to write a code which
wanted output xls file:
table 1:
sume of first col: sum of say 3rd col:
txt1 txt3
txt5 txt7
txt4 txt2
table2: <same as above>
Plz dont misunderstand me point me to site which has c# code to do this or atleast give me an overview or idea about implenting this in c#.
|
|
|
|
|
taurusone wrote: yes i know it is not restaurant and i am not ordering, it a request.
Aight, we'll walk you through it, from start to finish. Can you paste the sourcecode to read/write a textfile here? Once you got that, you're halfway.
taurusone wrote: Plz dont misunderstand me point me to site which has c# code to do this or atleast give me an overview or idea about implenting this in c#.
Luc gave you an idea, even though it requires some basic programming-skills. There's little chance that anyone will post code "at request" that does "what I want".
..but we can walk you trough writing such a thing. Seems the best idea, as that'd mean that you'll understand every line of code, and will be able to change it when required. So, let's see your code on reading/writing text files
Bastard Programmer from Hell
|
|
|
|
|
So you want the first and third columns only.
So write a program that extracts the first and third columns and write those to a text file.
Then you can use excel to open the file using a CSV format. Excel actually allows for a choice of what is used as a separator. Myself I use tab.
|
|
|
|
|
This article[^] will show you how to do it.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Hi all
I am creating a software that contains a dynamic chart showing temperature and depth . The temperature varies all the time in the time .I use a usercontrol that has several colors(gradient).For example the 30 degree has been shown as Red and as the temperature decreases it will change to Blue.Now i am using static gradient . Now i need to update as the temperature changes the gradiant must also be changed according to the value of the temperature.
that is if the temperature suddenly falls from 30 degree to 5 degree the color must have to change from Red to Blue.
|
|
|
|
|
The quickest and dirtiest way (and I am assuming you are using binding here) would be to have a custom converter class which accepts the temperature as an input, and returns the relevant colour as the output. What you need to look at is implementing an IValueConverter - and hook this up in a binding. For instance:
BackgroundColor="{Binding Temperature, Converter={StaticResource myTemperatureToColorConverter}}" Note that you would have to add a reference to your colour converter in a resources section like this:
<converters:TemperatureToColorConverter x:Key="myTemperatureToColorConverter" /> I leave the actual implementation of the converter class to you, but you should find plenty of source samples on the web, as this is a very trivial task.
BTW - don't surround your text in the <pre> tags, these should be reserved for code samples.
Second BTW - you should have asked this in the WPF forum.
|
|
|
|