Hi,
I have a requirement like I need to transpose a row into column.
We are using aspose.cells for .net.
Please help me …
Regards,
Srikanth G
Hi,
I have a requirement like I need to transpose a row into column.
We are using aspose.cells for .net.
Please help me …
Regards,
Srikanth G
Hi,
Thanks for your posting and considering Aspose.Cells.
You can transpose rows into columns or vice versa using the PasteOptions.Transpose property.
Please see this sample code for illustration of this feature. I have attached the source excel file used in this code and the output excel file generated by it for your reference.
C#
String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Range range = cells.CreateRange(“B3:E6”);
Range dRange = cells.CreateRange(“H5:K8”);
PasteOptions opts = new PasteOptions();
opts.Transpose = true;
dRange.Copy(range, opts);
workbook.Save(filePath + “.out.xlsx”, SaveFormat.Xlsx);
Hi Shakeel Faiz,
thanks for the quick reply.
Actually I don’t know the range. I need to select dynamically based on some condition.
in that case how can I do that …
thanks & Regards,
Srikanth G
Hi Srikanth,
Thanks for your sound question and using Aspose.Cells.
Please see the following modified code. Now you can select any cell of your choice where you want to copy your range as transpose dynamically.
I have attached the output excel file generated with the following code. Here you can see, I have copied range to cell E12. You can try the code with any cell you like.
C#
String filePath = “F:\Shak-Data-RW\Downloads\source.xlsx”;
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
Range range = cells.CreateRange(“B3:E6”);
string yourDesiredCell = “E12”;
int firstRow, firstColumn;
CellsHelper.CellNameToIndex(yourDesiredCell, out firstRow, out firstColumn);
Range dRange = cells.CreateRange(firstRow, firstColumn, range.ColumnCount, range.RowCount);
PasteOptions opts = new PasteOptions();
opts.Transpose = true;
dRange.Copy(range, opts);
workbook.Save(filePath + “.out.xlsx”, SaveFormat.Xlsx);