c# - 如何将三个单列拆分为一大列?
问题描述
我的数据表中有这种类型的数据。想象一下 ("2019_WK1", "2019_WK2", "2019_WK3") 是三个列名,所以我需要在一个大的合并单元格中拆分 2019(年),(上层 "WK1"、"WK2"、"WK3" ) C# 中的列单元格。
使用 Excel = Microsoft.Office.Interop.Excel;
以下是我的数据表代码:
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
Excel.Range chartRange;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//add data
xlWorkSheet.Cells[1, 1] = "Retailer";
xlWorkSheet.Cells[1, 2] = "Brand";
xlWorkSheet.Cells[1, 3] = "2019_WK1";
xlWorkSheet.Cells[1, 4] = "2019_WK2";
xlWorkSheet.Cells[1, 5] = "2019_WK3";
xlWorkSheet.Cells[2, 1] = "Lulu";
xlWorkSheet.Cells[2, 2] = "Perisil";
xlWorkSheet.Cells[2, 3] = "25";
xlWorkSheet.Cells[2, 4] = "26";
xlWorkSheet.Cells[2, 5] = "23";
xlWorkSheet.Cells[3, 1] = "Lulu";
xlWorkSheet.Cells[3, 2] = "Ariel";
xlWorkSheet.Cells[3, 3] = "26";
xlWorkSheet.Cells[3, 4] = "28";
xlWorkSheet.Cells[3, 5] = "29";
xlWorkSheet.Cells[4, 1] = "Danube";
xlWorkSheet.Cells[4, 2] = "Omo";
xlWorkSheet.Cells[4, 3] = "27";
xlWorkSheet.Cells[4, 4] = "28";
xlWorkSheet.Cells[4, 5] = "30";
xlWorkSheet.Cells[5, 1] = "Danube";
xlWorkSheet.Cells[5, 2] = "Tide";
xlWorkSheet.Cells[5, 3] = "24";
xlWorkSheet.Cells[5, 4] = "23";
xlWorkSheet.Cells[5, 5] = "29";
xlWorkSheet.Cells[6, 1] = "Bin Dawood";
xlWorkSheet.Cells[6, 2] = "Perisil";
xlWorkSheet.Cells[6, 3] = "26";
xlWorkSheet.Cells[6, 4] = "27";
xlWorkSheet.Cells[6, 5] = "28";
xlWorkBook.SaveAs("d:\\csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlApp);
releaseObject(xlWorkBook);
releaseObject(xlWorkSheet);
MessageBox.Show("File created !");
}
我需要像这种类型的列
____________________________
| 2019 |
|___________________________|
| WK1 l WK2 l WK3 |
|________l________l_________|
| 25 | 26 | 23 |
| 27 | 29 | 24 |
___24________25_______22_____
解决方案
推荐阅读
- vue.js - 使用 vue.js 和 chartist.js 创建一个跟踪余额进度的图表
- kubernetes - 从另一个 K8s 容器访问 K8s 容器属性
- python - 如何在 django 中使用过滤条件获取所有详细信息?
- java - Java 到 Kotlin - 哪种数据类型可以处理传入的 ArrayTable
在科特林? - android - 在Android上以编程方式打开屏幕的不被弃用的方式是什么
- c# - 如何在 listview 上读取选定的 txt 文件?
- typescript - 如何在 TypeScript 中访问这三个类
- rx-java - 如何在 RxJava 中对两个列表进行分组?
- php - PHP:如何解析 Lilypond 文件?
- c# - 电报机器人:GetUpdates 冲突