定制的excel订购 [英] Customized excel ordering

查看:63
本文介绍了定制的excel订购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我有这个excel文件,我必须做一些专栏。



如果我需要按递增顺序对数字进行排序,我使用以下代码:



Hello,

I have this excel file and I have to do some sort of columns.

In case I need to order columns with numbers in increasing order I used the following code:

Excel.Worksheet sheet = (Excel.Worksheet)xlWorkBook.Sheets[1];
sheet.Sort.SortFields.Clear();
sheet.Sort.SortFields.Add(sheet.Range["E13:E100"], Excel.XlSortOn.xlSortOnValues, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortDataOption.xlSortNormal);
sheet.Sort.SortFields.Add(sheet.Range["D13:D100"], Excel.XlSortOn.xlSortOnValues, Excel.XlSortOrder.xlAscending, Type.Missing, Excel.XlSortDataOption.xlSortNormal);
sheet.Sort.SetRange(sheet.Range["A13:AP100"]);
sheet.Sort.Apply();
xlWorkBook.Save();





我的问题是我必须整理一个有一些字母的列但是特别是我不需要按字母顺序对它进行排序,而是按照精确的顺序排序:

首先,我希望记录字母为GV,然后是BU,GNYE,然后是BK。



非常感谢



我尝试过:



到现在为止我还不知道如何运行代码



My problem is that I have to put in order a column that has some letters but in particular I do not have to sort it in alphabetical order but with a precise order:
First I would like to have the records with the letters GV, then BU, GNYE and then BK.

Thanks so much

What I have tried:

Until now I do not know how to run the code

推荐答案

Excel中的替代方案是拥有一个额外的列,如果需要隐藏,其中包含将这些项目映射到数字的公式,例如(未经测试)

An alternative within Excel would be to have an additional column, hidden if necessary that contains a formula to map those items to a number e.g. (untested)
= IIF(A1="GV",1,IIF(A1="BU", 2, IIF(A1="GNYE",3,4)))



然后对该列进行排序


Then sort on that column


使用数据 - >排序菜单项,然后选择排序键列。然后,您可以添加自定义列表以告诉它要排序的顺序。



似乎Interop中没有此选项。



我只能建议将数据提取到网格或通用列表。然后,您可以将项目按您需要的顺序排序,并将它们写回电子表格。
Use the Data -> Sort menu item, and select the sort key column. You can then add a Custom List to tell it the order to sort.

Seems that this option is not available in the Interop.

I can only suggest extracting the data to a grid or generic list. You can then sort the items into whatever order you require and write them back to the spreadsheet.


这篇关于定制的excel订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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