This project has moved and is read-only. For the latest updates, please go here.

Merge and resize columns

Jan 26, 2016 at 9:44 AM
Edited Jan 26, 2016 at 9:47 AM
Hi,

I've taken the last version of EPPlus (4.0.5), I hoped my problems are solved. But No.

I 've problems with merge and resize columns after all my data were filled.
 using (ExcelPackage package = new ExcelPackage())
            {
                //ExcelWorkbook wkbook = new ExcelWorkbook();
                ExcelWorksheet currWkSheet ;

                int mancheId = 1;
                foreach (Manche manche in emission.Manches)
                { 
                    int questionID = 1;
                    foreach (Question question in manche.questions)
                    {
                        string worksheetName = "RD_" + mancheId.ToString();
                        if (mancheId > 1)
                        {
                            worksheetName += "." + questionID.ToString();
                        }

                        currWkSheet = package.Workbook.Worksheets.Add(worksheetName);

                        // LIGNE 1
                        currWkSheet.Cells["A1"].Value = manche.nom;
                        currWkSheet.Cells["B1"].Value = question.type;

                        currWkSheet.Cells["C1"].Value = emission.Nom;
                        //currWkSheet.Cells["C1"].Style.WrapText = true;

                        currWkSheet.Cells["D1"].Value = " ";
                        currWkSheet.Cells["E1"].Value = " ";
                        currWkSheet.Cells["F1"].Value = " ";
                        currWkSheet.Cells["G1"].Value = " ";
                        
                        currWkSheet.Cells["A1:G1"].Style.Font.Bold = true;

                        currWkSheet.Cells["A1:G1"].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;
                        currWkSheet.Cells["A1:G1"].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
                        currWkSheet.Cells["A1:G1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                        currWkSheet.Cells["A1:G1"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Transparent);
                        currWkSheet.Cells["A1"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Blue);
                        currWkSheet.Cells["C1"].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Gray);

[...] bla bla bla

    

                        currWkSheet.Cells["B1:E1"].Merge = true;
                        currWkSheet.Cells["B2:E2"].Merge = true;
                        currWkSheet.Cells["B3:E3"].Merge = true;

                        currWkSheet.Column(1).Width = 10;
                        currWkSheet.Column(2).Width = 25;
                        currWkSheet.Column(3).Width = 10;
                        currWkSheet.Column(4).Width = 25;
                        currWkSheet.Column(5).Width = 10;
                        currWkSheet.Column(6).Width = 18;
                        currWkSheet.Column(7).Width = 10;

                        questionID++;
                    }
                    mancheId++;

                }
       }
I tried to use currWkSheet.Cells["A:A"].AutoFitColumns(10) for exemple, but it doesn't work.

After merging, I want to resize my columns for printing document.

How do I suppose to do ?

Thx
Jan 26, 2016 at 12:05 PM
Sorry

I've found my mystake.

After create my XLSX file, I transform it onto a pdf file.

In my code on pdf transformation, I had this code : "wsk.Columns.AutoFit();" so my column size was disabled. I have commented this, and it's ok now.

Sorry for disturb. You could to delete my tribute.