转换以下Excel VBA代码以在C#中进行排序 [英] Convert the following Excel VBA code for sorting in C#

查看:233
本文介绍了转换以下Excel VBA代码以在C#中进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我将以下Excel VBA代码转换为C#-这是在excel中按单元格颜色排序的方法:-

在excel文件中有一个表,其中的列为TowerName,Incident,Problem和Change.事件列包含以红色,黄色和绿色作为单元格颜色的值.我需要对该表进行排序,以使其在事件"列上按红色排序,然后按黄色排序.我已经记录了执行此操作的宏,该宏已复制到上面.请帮助我如何在C#控制台应用程序中以编程方式执行此操作.

我需要将这段VBA代码转换为C#
-------------------------------------------------- -------------------------

Can anyone help me to convert the following Excel VBA code to C# - this is sorting on cell colour in excel :-

There is a table in an excel file with columns as TowerName, Incident, Problem and Change. The column Incident contains values as cell colour in Red, yellow and Green. I need to sort this table such that it will sort on Incident column by red colour then by yellow colour. I have recorded macro for doing this which is copied above. Please help me how would i do this programatically in c# console application.

I need to convert this piece of VBA code to C#
---------------------------------------------------------------------------

Range("E3:H18").Select 
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear 
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range("F4:F18"), _ xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0, 0) 
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add(Range("F4:F18"), _ 
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 255, 0) 
With ActiveWorkbook.Worksheets("Sheet1").Sort 
.SetRange Range("E3:H18") 
.Header = xlYes 
.MatchCase = False 
.Orientation = xlTopToBottom 
.SortMethod = xlPinYin 
.Apply 
End With

推荐答案

Range["E3:H18"].Select();
ActiveWorkbook.Worksheets["Sheet1"].Sort.SortFields.Clear();
ActiveWorkbook.Worksheets["Sheet1"].Sort.SortFields.Add(Range["F4:F18"], _ xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 0, 0); 
ActiveWorkbook.Worksheets["Sheet1"].Sort.SortFields.Add(Range["F4:F18"], _ 
xlSortOnCellColor, xlAscending, , xlSortNormal).SortOnValue.Color = RGB(255, 255, 0) ;
using (ActiveWorkbook.Worksheets["Sheet1"].Sort())
{
.SetRange Range["E3:H18"] ;
.Header = xlYes ;
.MatchCase = False ;
.Orientation = xlTopToBottom ;
.SortMethod = xlPinYin ;
.Apply(); 
}



请参阅下面的链接,将vb代码转换为c#(或其他语言转换)
http://www.developerfusion.com/tools/convert/vb-to-csharp/ [^ ]

祝您编码愉快!
:)



refer below link to convert vb code to c# (or other language conversion)
http://www.developerfusion.com/tools/convert/vb-to-csharp/[^]

Happy Coding!
:)


这篇关于转换以下Excel VBA代码以在C#中进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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