Not Yet Answered # Excel Sorting

LizR 171 Discussion Starter ronnysaid Discussion Starter ronnysaid Discussion Starter ronnysaid LizR 171 Discussion Starter ronnysaid Clawsy 1 Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...

0

Many - have a search on using excel from c# and reading values.. and controlling excel - theres a few ways you could go about it.

0

thank you for replies, but i made some search but i guess i missed the right direction on it, could anyone of you please point me to the right direction??

0

ok, it seems that noone knows the answer ,just guesses, i made lots of searches and after that i posted this questions.

Thank you all for your replies.

0

Liz, i didnt ask you to do it for me, i was seeking help in answering this question not a help with how to do a search!!!!!!! i was a big contributor in MS forums, and i know how forums work and how to make searches.

anyway, just answering your guesses, you cant get the sort information stored in the dialog as its perserved by excel application itself, so all of you said "Yah and many" specially you Liz without even knowing if its possible or not. and RamyMahrous posted a google search link with "C# work with Excel" keywords!!!

at least post keywords like "C# +excel +get +sort +data". with "+" sign telling the google engine to include all of these keywords in its search.

anyhow, i wouldnt post a question on forums without having an intensive search prior that and would never guess the answer without knowing it.

im just posting the answer to let anyone who has the same question to know that its not possible and the workaround is to do the following:

1. Get the last sort by calling Worksheet.Sort.Rng (do remember to check

Worksheet.Sort.SortFields.Count if its > 0 prior that call, Worksheet.Sort will return the last sort done by the end user).

2. loop over the data and check if its in the correct order as you expect it or not.

0

Actually there are enormous amounts of excel interactions listed, you have many options wether you read the data to c# and put it back, or just ask Excel to do the work for you. What you havent done is actually plan what you want. There are examples of all of this which is why I tell you to search.

Oh and there you go, you found an answer.. so, I guess you managed to work it out by readint anyway.

It surprises me that anyone feels they can program, when they cant do research. Searching on google should be fairly intuative by now, if you didnt think to search for c# excel data sort.. such as the keywords listed, it just doesnt look like people try.. when you can pretty much copy and paste the question into google and get the answer.

0

RamyMahrous and Liz, im not mad, thank you for your replies. i do appreciate any kind of reply whatever it is as you guys had the time to read my question and thank you for that :)

Liz, i got the answer from the Bytes forum, the approach i took was already done before even posting the question, but i just wanted to know if there is an easier way to do it or if excel supports such kind of interaction, it appears to be that xlDialogSort preserve these data to itself according to the confirmation i got from the bytes forum.

0

you should start learning using Microsoft.Office.Interop.Excel library. add it from COM reference. I give you here a simple example. I just import a string in Excel in cell (1,1). If you do this, try to learn more using auto-complete and surfing the web.

```
//the library
using Microsoft.Office.Interop.Excel;
//variables
Microsoft.Office.Interop.Excel.ApplicationClass exApp = new ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook objBook;
Microsoft.Office.Interop.Excel.Worksheet objSheet;
try
{
object missing = System.Reflection.Missing.Value;
exApp.Visible = true;
objBook = exApp.Workbooks.Add(missing);
objSheet = (Microsoft.Office.Interop.Excel.Worksheet)objBook.Sheets["Sheet1"];
objSheet.Name = "myTable";
objSheet.Cells[1,1]="Helloooooooooooooooooooooo!";
objSheet.get_Range("A1", "B1").EntireColumn.AutoFit();//my text is long so i AutoFit the columns.
}
// in case of exception, we show it
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
```

Hope this helps you get experience with Excel :)

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

When I execute this progammatically, I get a table with row heights much larger than when I do this manually.

Note : Sel is the Word.Selection object and the Clipboard contains an Excel Table.

```
public void AddClipboard()
{
Sel.PasteExcelTable(false,false, false);
var t = Sel.Tables[Sel.Tables.Count];
t.AutoFitBehavior(Word.WdAutoFitBehavior.wdAutoFitContent);
}
```

the function that I created to find the ...