I am trying to create a .Net application to edit a excel file by deleting some columns and keeping the columns which we need and then removing the duplicate values based on the first column which is going to be the Serial no. which should have a check to have 6 digits by default like 2563 should be displayed as 002563.
Please help me..
EDIT Code copied from OPs's comment:
Public Function GetAllFileContents(ByVal path As String, ByRef errorMessage As String) As IList(Of String)
Dim contents = New List(Of String)
Try
Dim files = Directory.GetFiles(path, "*.xls")
If (files.Length = 0) Then errorMes开发者_如何转开发sage = "Please select the files"
For Each file In files
contents.Add(System.IO.File.ReadAllText(file, Encoding.Default))
Next
Catch ex As Exception
errorMessage = ex.Message
End Try
Return contents
I am trying to create something different by not only letting me do it for excel files but for say txt and csv files along with it. Removing all the values which I dont want and removing the duplicates and then if possible putting a check on the first column of data that the serial number number should have minimum of 6 characters and then The output file should have all the details in Uppercase
Assuming that this code doesn't need to run on a server or similar and that you have a version of MS Office installed on the machine where it'll run, I'd suggest that the easiest way would be to use Excel Automation. Here's an article that should show you enough to get started: How to automate Microsoft Excel from Visual Basic .NET
If you use that code first, you should be able to figure out how to extract all the data you need, and then you can manipulate it in memory and later just write it back as needed.
Edit: Added more info below:
Look at the line oSheet.Cells(1, 2).Value = "Last Name"
in that sample, that sets a cell to a specific value, just change that to be something like myVariable = oSheet.Cells(1, 2).Value
and you'll get the value for that cell instead. Just loop through getting out the values for all the cells in the column you're interested in. Then just look at this article for info about how to write the values to a text file: How to: Write Text to a File
If there are a lot of values, then there's more efficient ways of doing it, but if you get this working first so that you understand this, it would then not be too difficult to make it faster.
精彩评论