Aspose cells 有没有excel中 行列粘贴转置的功能


#1

如题 excel中
图片.png (11.8 KB)
有能将行和列反转过来的功能 aspose cells 能操作吗 谢谢


#2

@beoned,
您能否分享用MS Excel创建的输入模板文件和预期输出文件进行分析。


#3

test.zip (13.3 KB)
1563438170(1).png (7.7 KB)
参考附件的图片中方法和文件中结果


#4

@beoned,
您可以使用Aspose.Cells API转置范围。 确保将其粘贴到当前范围之外,然后将其复制到原始或所需的单元格。 稍后根据您的要求删除不必要的范围。

Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(@"D:\test\before.xlsx");
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
Aspose.Cells.Cells cells = worksheet.Cells;
Aspose.Cells.Range range = cells.CreateRange("A1:J8");
string yourDesiredCell = "C9"; //Outside current range
int firstRow, firstColumn;
Aspose.Cells.CellsHelper.CellNameToIndex(yourDesiredCell, out firstRow, out firstColumn);
Aspose.Cells.Range dRange = cells.CreateRange(firstRow, firstColumn, range.ColumnCount, range.RowCount);
Aspose.Cells.PasteOptions opts = new Aspose.Cells.PasteOptions();
opts.Transpose = true;
dRange.Copy(range, opts);
workbook.Save(@"D:\test\out.xlsx", Aspose.Cells.SaveFormat.Xlsx);