2014-12-08 11 views
13

Ich habe ein Problem, eine Reihe von verbundenen Zellen zu horizontalen Ausrichtung zentriert bekommen. Die Ausrichtung bleibt wie links. Hier ist mein Code.Wie Horizontalignment Center fusionierte Zellen in EPPlus

ws.Cells[lStartColumn + lStartRow].Value = gPortfolioName + " - " + lTypeOfPortfolioPerf + " Performance Update"; 
ws.Cells[lStartColumn + lStartRow + ":" + lEndColumn + lEndRow].Merge = true; 
ws.Cells[lStartColumn + lStartRow + ":" + lEndColumn + lEndRow].Style.HorizontalAlignment = ExcelHorizontalAlignment.CenterContinuous; 
ws.Cells[lStartColumn + lStartRow + ":" + lEndColumn + lEndRow].Style.Font.Size = 14; 
ws.Cells[lStartColumn + lStartRow + ":" + lEndColumn + lEndRow].Style.Font.Color.SetColor(bgTitleColor); 
ws.Cells[lStartColumn + lStartRow + ":" + lEndColumn + lEndRow].Style.Font.Bold = true; 

Antwort

31

Sollte sein:

worksheet.Cells["A2:A4"].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; 

Aber ich denke, Sie das letzte Mal tun es werden sollte, da einige Styling Änderungen Ihre Ausrichtung beeinflussen können. Die Reihenfolge ist wichtig.

3

Zentrum align Zellen verschmolzen

// ws.Cells[Rowstart, ColStart, RowEnd, ColEnd] 

    ws.Cells[1, 1].Value = "BILL OF MATERIALS"; 
    ws.Cells[1, 1, 1, 7].Merge = true; //Merge columns start and end range 
    ws.Cells[1, 1, 1, 7].Style.Font.Bold = true; //Font should be bold 
    ws.Cells[1, 1, 1, 7].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; // Alignment is center 
    ws.Cells[1, 1, 1, 7].Style.Font.Size = 25; 
Verwandte Themen