2016-08-11 3 views
-1

Ich habe eine Reihe von Spaltenüberschriften, die ich einrichten wie so:Warum werden die Textbeschriftungen diesen Zellen nicht hinzugefügt (EPPlus)?

private static readonly int COLUMN_HEADER_ROW = 6; 
private static readonly int COLUMN_COUNT = 15; 
private static readonly int COLUMN_HEADER_ROW_HEIGHT = 48; 
private static readonly int PLATYPUS_DISTRIBUTOR_COLUMN = 1; 
private static readonly int RESTAURANT_LOCATION_COLUMN = 2; 
private static readonly int RESTAURANT_LOCATION_COLUMN_WIDTH = 36; 
private static readonly int TOTAL_PACKAGE_COUNT_COLUMN = 15; 

. . . 

// Add column headers 
using (var rowRng = deliveryPerformanceWorksheet.Cells[COLUMN_HEADER_ROW, PLATYPUS_DISTRIBUTOR_COLUMN, COLUMN_HEADER_ROW, COLUMN_COUNT]) 
{ 
    rowRng.Style.Font.Name = fontForSheet; 
    rowRng.Merge = true; 
    rowRng.Style.Font.Size = 12; 
    rowRng.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; 
    rowRng.Style.VerticalAlignment = ExcelVerticalAlignment.Center; 
    rowRng.Style.Fill.PatternType = ExcelFillStyle.Solid; 
    deliveryPerformanceWorksheet.Row(COLUMN_HEADER_ROW).Height = COLUMN_HEADER_ROW_HEIGHT; 
    rowRng.Style.Fill.BackgroundColor.SetColor(Color.LightSkyBlue); 
    // set borders 
    rowRng.Style.Border.BorderAround(ExcelBorderStyle.Thin); 
    rowRng.Style.Border.Top.Style = ExcelBorderStyle.Thin; 
    rowRng.Style.Border.Left.Style = ExcelBorderStyle.Thin; 
    rowRng.Style.Border.Right.Style = ExcelBorderStyle.Thin; 
    rowRng.Style.Border.Bottom.Style = ExcelBorderStyle.Thin; 
} 

ich dann versuchen, Text in dieser Zeile zu jeder Zelle wie so hinzuzufügen:

// Col A 
using (var distributorCell = deliveryPerformanceWorksheet.Cells[COLUMN_HEADER_ROW, PLATYPUS_DISTRIBUTOR_COLUMN]) 
{ 
    distributorCell.Value = "Platypus Distributor"; 
    distributorCell.Style.Font.Bold = true; 
} 

// Col B 
using (var sunRestaurantLocationCell = deliveryPerformanceWorksheet.Cells[COLUMN_HEADER_ROW, RESTAURANT_LOCATION_COLUMN]) 
{ 
    sunRestaurantLocationCell.Value = "Restaurant Location"; 
    deliveryPerformanceWorksheet.Column(RESTAURANT_LOCATION_COLUMN).Width = RESTAURANT_LOCATION_COLUMN_WIDTH; 
    sunRestaurantLocationCell.Style.Font.Bold = true; 
} 

. . . 

// Col O 
using (var totalPackageCountHeaderCell = deliveryPerformanceWorksheet.Cells[COLUMN_HEADER_ROW, TOTAL_PACKAGE_COUNT_COLUMN]) 
{ 
    totalPackageCountHeaderCell.Value = String.Format("Total Package{0}Count", Environment.NewLine); 
    totalPackageCountHeaderCell.Style.WrapText = true; 
    totalPackageCountHeaderCell.Style.Font.Bold = true; 
} 

... aber der einzige Wert, der in eine Zelle geschrieben wird, ist "Platypus Distributor" und wird in Spalte 3 anstatt in Spalte 1 platziert.

Warum wird nur ein Textwert zugewiesen und warum wird er falsch platziert Zelle/Spalte?

+0

Bitte [siehe] (http://meta.stackexchange.com/questions/19190/should-questions-include- Tags in ihren Titeln) - und was hat das mit Excel zu tun? – pnuts

Antwort

1

einfach einen Kommentar oder entfernen Sie die Zuordnung "Merge", nämlich diese Zeile:

rowRng.Merge = true; 
Verwandte Themen