答案 0 :(得分:1)
好吧,你不能在MS Excel的单个单元格中输入两个值。我认为您可以通过合并/取消合并某些单元格并相应地将值输入相关单元来完成您的任务。请参阅下面的示例代码以供参考,它涵盖并设计附加表格/矩阵的某些部分。请参考它,您可以编写自己的代码(通过Aspose.Cells API)来完成相应的任务:
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
//Input header value to B1 cell (later we will merge it: B1:C1 --> B1
worksheet.Cells[0, 1].PutValue("header2");
//Input value to B2 cell that would be merged with B3 to become B2.
worksheet.Cells[1, 1].PutValue(1);
//Input value to C2 cell.
worksheet.Cells[1, 2].PutValue(2);
//Input value to C3 cell.
worksheet.Cells[2, 2].PutValue(3);
//Set row heights for 2nd and third rows for the cells accordingly.
worksheet.Cells.SetRowHeight(1, 25);
worksheet.Cells.SetRowHeight(2, 25);
//Merging cells.
//Merge B1:C1 --> B1
worksheet.Cells.Merge(0, 1, 1, 2);
//Merge B2:B3 --> B2
worksheet.Cells.Merge(1, 1, 2, 1);
//Formatting cells and ranges.
//Creating a range that spans over the all data cells of a worksheet
var range = worksheet.Cells.CreateRange("B1", "C3");
//Create a Style object.
Style colstyle = workbook.CreateStyle();
colstyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
colstyle.HorizontalAlignment = TextAlignmentType.Center;
StyleFlag flag = new StyleFlag();
flag.Borders = true;
flag.HorizontalAlignment = true;
//Apply the style to the range
range.ApplyStyle(colstyle, flag);
workbook.Save("e:\\test2\\output__mergedcells.xlsx");
请参阅Excel中的输出Excel文件的屏幕截图供您参考: http://prntscr.com/8rbc0i
我是Aspose的开发人员/传播者。