如何将三个单列拆分成一个大列? [英] How to split three single columns into one big column?

查看:71
本文介绍了如何将三个单列拆分成一个大列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Datatable中有这种类型的数据。想象一下(2019_WK1,2019_WK2,2019_WK3)是三个列的名称,所以我需要在一个大的合并单元格(上WK1,WK2,WK3)中拆分2019(年) )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 );



//添加数据

xlWorkSheet.Cells [1,1] =零售商;

xlWorkSheet.Cells [1,2] =品牌;

xlWorkSh eet.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] =多瑙河;

xlWorkSheet.Cells [4,2] =Omo;

xlWorkSheet.Cells [4,3] =27;

xlWorkSheet.Cells [4,4] =28;

xlWork Sheet.Cells [4,5] =30;



xlWorkSheet.Cells [5,1] =多瑙河;

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:​​\\\\ [[[[[[[[[[[[ misValue,misValue,misValue);

xlWorkBook.Close(true,misValue,misValue);

xlApp.Quit();



发布eObject(xlApp);

releaseObject(xlWorkBook);

releaseObject(xlWorkSheet);



MessageBox.Show (文件创建!);

}



我尝试过:



我需要这种类型的栏目



____________________________

| 2019 |

| ___________________________ |

| WK1 l WK2 l WK3 |

| ________ l ________ l _________ |

| 25 | 26 | 23 |

| 27 | 29 | 24 |

___ 24 ________ 25 _______ 22 _____

解决方案

如果我理解正确,您希望合并三个列上方的标题。这已在此处得到解答:使用C#在Excel中合并单元格 - Stack Overflow [ ^ ]

I've got this type of data in my Datatable. Imagine that ("2019_WK1", "2019_WK2", "2019_WK3") is the three column names and so i need to take split 2019(year) in one big merged cell, (Upper "WK1", "WK2", "WK3") column cells in C#.

using Excel = Microsoft.Office.Interop.Excel;

Below are my datatable code:

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 !");
}

What I have tried:

I need like this type of columns

____________________________
| 2019 |
|___________________________|
| WK1 l WK2 l WK3 |
|________l________l_________|
| 25 | 26 | 23 |
| 27 | 29 | 24 |
___24________25_______22_____

解决方案

If I understand you correctly, you want to merge the header above three of your columns. This has been answered here: Merging Cells in Excel using C# - Stack Overflow[^]


这篇关于如何将三个单列拆分成一个大列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆