1

I have a requirement where I need to export data from excel file to a specified format(xml, text or even excel).The problem is client can map any column and then want to export it to a specific format to make some kind of report. If he ticks cell E1 and D1 in form, he needs to be able to export all the values of E1 and D1 under the header of E1 and D1. Please suggest. Thanks Yogesh

1 Answer 1

1

You can use a variable to handle the cell you want to take the information from. Assume that you put all the "cell" checkboxes in within a panel called pnlCells. Each checkbox goes with its corresponding Cell name - or Tag. I prefer putting the cell name into the checkbox's Tag. This is a simple way to do it:

In case you don't know how to work with excel inside vb.net.... here is some basic code

Dim oExcel as Microsoft.Office.Interop.Excel.Application
Dim oBook As Microsoft.Office.Interop.Excel.Workbook
Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet
oExcel = CType(CreateObject("Excel.Application"), Microsoft.Office.Interop.Excel.Application)
oBook = oExcel.Workbooks.Open(ExcelFilePath)
oSheet = CType(oBook.Worksheets(SheetName), Microsoft.Office.Interop.Excel.Worksheet)

'This will get the excel sheet you are currently working on and store in in the variable named oSheet.

Dim pos as String = ""
For each CellCheck as Control in pnlCells.Controls
    if CellCheck.GetType() is GetType(CheckBox) Then
        Dim Check as CheckBox = CType(CellCheck, CheckBox) 'Get the checkbox
        if Check.Checked = true then
             pos = Check.Tag 'This will get you the cells you need
        end if
        txtData.text = oSheet.Range(pos).Value.ToString 'Extract data....
        HandleData(txtData.text) 'Handling data goes here
    end if
Next

This little piece of code will loop through all of the checkbox in panel, and with each checked checkbox, get the corresponding cell content from the excel sheet.

Guide to write data into an xml file using xmlWriter: http://www.dotnetperls.com/xmlwriter-vbnet

I can't provide any specific answer, because I don't know what is the data in your excel file, hence I can't write out the format file. But i believe what I provided here is basically enough for you to do your work.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for this :).. I want this data to be formatted to xml or text or in another excel sheet as per client need.
In that case, you should also put a set of radio button, and write the appropriate code to write out the data in the desired format file depend on which button is chosen.
correct! but can you just guide how to proceed to write xml from excel data

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.