Click here to Skip to main content
16,004,453 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello guys,

Maybe it was discussed but i don't find something to fit my problem ... I have the following code

C#
Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();

if (xlApp == null)
{
    Console.WriteLine("Excel is not properly installed!!");
    return;
}

Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
Excel.Range xlRange;

xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
xlWorkSheet.Name = "Raport generated";
xlWorkSheet.Cells[1, 1] = "ceva";
xlWorkSheet.Cells[2, 1] = "ceva";
xlWorkSheet.Cells[3, 1] = "ceva";
xlWorkSheet.Cells[4, 1] = "ceva";
xlWorkSheet.Cells[5, 1] = "ceva";
xlWorkSheet.Cells[6, 1] = "ceva";
xlWorkSheet.Cells[7, 1] = "ceva";
xlWorkSheet.Cells[8, 1] = "ceva";



xlWorkBook.SaveAs("D:\\Excel.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();


Console.ReadKey();


And i want to group the rows from 2 -> 8(having the "+" sign in my excel and when i press it to expand), how can i do that ?

Thank you in advance.

What I have tried:

C#
xlWorkSheet.get_Range(xlWorkSheet.Cells[2, 1], xlWorkSheet.Cells[8, 1]).Group();
Posted
Updated 2-Nov-16 4:12am

C#
Excel.Range xlRange = xlWorkSheet.get_Range(xlWorkSheet.Cells[2, 1], xlWorkSheet.Cells[8, 1]);
            xlRange.rows.Group(misValue, misValue, misValue, misValue);
            xlRange.rows.OutlineLevel = 1;


try this. This i had already used in my program
 
Share this answer
 
Comments
serbanov 2-Nov-16 2:58am    
Something like this i have tried too, now i'm generating an excel file to test it, thank you !

The problem is i can't use "A1" to "A10" because i can expand even to "AA" or "ZZZ" to understand what kind of excel i'm generating. I iterate over 200 files and use their content. It's a tool i use to iterate through .C and .h files for a company. I will mark as solve solution your post, thank you.
C#
string _tempPath = _tempRowNb.ToString() + _row.ToString();

Excel.Range myRange = xlWorkSheet.Rows[_tempPath, misValue] as Excel.Range;
myRange.OutlineLevel = 1;
myRange.Group(misValue, misValue, misValue, misValue);



This is my solution. Hope someone will use it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900