Exporting Excel to C#

前端 未结 6 859
青春惊慌失措
青春惊慌失措 2020-12-21 16:44

I have to port excel file which business guys are using to calculate final price to C# so I can later use this algorithm in Asp.Net application. This is something I will be

6条回答
  •  无人及你
    2020-12-21 17:39

    Strictly speaking, it doesn't make a lot of sense to "export Excel to C#." This is because what you generally wish to export from Excel is data and C# is a programming language. Perhaps the question you're looking for is, "How can I make Excel data available to a program written in C#?"

    I used this write-up on C# Excel Interop Use as a starting point for reading Excel data from an application written in C#. That might be a good place to start to figure out how to make Excel data visible in C#.

    The other way to interpret your question is that you want to convert the Visual Basic for Applications (VBA) code within an Excel workbook to C#. If this is this case, you have a few options:

    • If it's not a lot of code, it probably would be easiest to simply convert the algorithms and procedures one at a time from VBA to C#.
    • This is a pretty ugly way, but you could import the VBA code into Visual Studio and upconvert it to VB.NET. Then you could use reflector to reflect the code to C#. Granted, this assumes that the VBA code is not tightly coupled to individual Excel objects (worksheets, rows, cells, ranges, etc.); if it's anything like the Excel "business applications" I've seen (and written), that's not likely to be the case.
    • For absolutely huge applications with decoupled code, you might consider VB6 to .NET migration solutions, like VB Migration Partner. I'm not sure how well these solutions will work if you have tightly coupled code, but if the workbook is huge, it might be something to look at.

提交回复
热议问题