简体   繁体   English

如何在VSTO中交换行(Excel)

[英]How to swap rows in VSTO (excel)

I would like to sort an excel spreadsheet from VSTO in C#. 我想在C#中从VSTO排序一个Excel电子表格。 But I want to use my own customer sorting technique and therefore can't use the Range.Sort method. 但是我想使用我自己的客户排序技术,因此不能使用Range.Sort方法。 I think if we can start with the ability to swap rows in a range that would be great. 我认为,如果我们可以在一个很好的范围内交换行的能力开始。

I think swapping rows would be way too slow for users but haven't tried it. 我认为交换行对用户来说太慢了,但是还没有尝试过。 The custom sorting in Excel is not suitable for you? Excel中自定义排序不适合您吗? I remember using it years ago in VBA (at that time probably Excel 2003) 我记得几年前在VBA中使用它(当时可能是Excel 2003)

If you are working with large amount of data (but also perfect for small) you can consider loading the range to an array, sort it via C# and then put it back to Excel. 如果您要处理大量数据(但也适合少量数据),则可以考虑将范围加载到数组中,通过C#对其进行排序,然后将其放回Excel。

System.Array dataArray = (System.Array)(range.Cells.Value2); //the value is boxed two-dimensional array

You will have to deal with formats then but I still assume that it will be much much much faster than manipulating with Excel range object 那时您将不得不处理格式,但是我仍然认为它会比使用Excel范围对象快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM