2014-01-09 41 views
1

我有以下示例代码。我遇到的问题是,在显示评论的那一部分的第一列中,它会被修剪。我喜欢做的是显示评论有它跨越所需的许多领域。目前它被修剪。我正在使用Excel 2010.使用ClosedXML单元格进行修剪

 var path = Path.Combine(driveLetter, "Sample", "Report_-Blank.xlsx"); 

    XLWorkbook workbook = new XLWorkbook(path); 

    //Read worksheet at position 1 i.e. First worksheet in excel 
    var ws = workbook.Worksheet(1); 

    // Facility Tested 
    ws.Cell(1, 19).Value = "TestLocation"; 
    ws.Cell(1, 19).Style.Font.FontSize = 20; 

    // Date of Collection 
    ws.Cell(2, 19).Value = "10/12/2013"; 
    ws.Cell(2, 19).Style.Font.FontSize = 20; 

    // Collector's Email 
    ws.Cell(3, 19).Value = "[email protected]"; 
    ws.Cell(3, 19).Style.Font.FontSize = 20; 

    // LabId 
    ws.Cell(5, 19).Value = "1344"; 
    ws.Cell(5, 19).Style.Font.FontSize = 20; 

    // Date Analyzed 
    ws.Cell(6, 19).Value = "12/3/2013"; 
    ws.Cell(6, 19).Style.Font.FontSize = 20; 


    // Sample # 
    ws.Cell(20, 1).Value = "1"; 
    ws.Cell(20, 1).Style.Font.FontSize = 20; 
    ws.Cell(20, 1).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; 

    // Location 
    ws.Cell(20, 2).Value = "Closed Loop1"; 
    ws.Cell(20, 2).Style.Font.FontSize = 20; 
    ws.Cell(20, 2).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; 

    // Comments 

    ws.Cell(22, 1).Value = "COMMENTS:"; 
    ws.Cell(22, 1).Style.Font.FontSize = 25; 
    ws.Cell(22, 1).Style.Font.Bold = true; 
    ws.Cell(22, 1).Style.Font.Underline = XLFontUnderlineValues.Single; 

    // Comment 1 
    ws.Cell(23, 1).Value = "Sample 1: Test is a test of how to display sample 1 [email protected] "; 
    ws.Cell(23, 1).Style.Font.FontSize = 20; 
    ws.Cell(23, 1).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; 

    MemoryStream ms = new MemoryStream(); 
    workbook.SaveAs(ms); 

    return ms; 

回答

2

如果右边的单元格为空Excel应显示注释单元格中空白单元格的文本。如果不是的话,你可以合并一些细胞获得更多的空间:

ws.Range(23, 1, 23, x).Merge().Value = "Sample 1: ..."; 

其中x是要合并的细胞数量。

如果没有足够的空单元格,使空间的评论,你也可以主动包装:

ws.Cell(23, 1).Style.Alignment.SetWrapText(true); 
相关问题