Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How can one test against merged cells in VB.NET?

I'm writing an app that retrieves data out of an excel sheet and feeds it
into an array.

I have it working with the following code, to the state where it works as
long as it doesn't come across a merged cell in it's range.

Code:
Try
            'create app session/objects
            Dim xlApp As Excel.Application
            Dim xlBook As Excel.Workbook
            Dim xlSheet As Excel.Worksheet
            Dim dataRange As Excel.Range
            'connect to file
            xlApp = CType(CreateObject("Excel.Application"), 
Excel.Application)
            xlApp.Workbooks.Open("c:\temp\product.xls")
            xlBook = xlApp.Workbooks(1)
            xlSheet = xlBook.Worksheets(1)

            'set the cell range and assign it to the array
            If txtRangeStart.Text = "" Or txtRangeEnd.Text = "" Then
                MessageBox.Show("You have to enter a group of cells to 
import!", "Information missing!", MessageBoxButtons.OK)
                Exit Sub
            Else
                excelRange = txtRangeStart.Text + ":" + txtRangeEnd.Text
            End If

            dataRange = xlSheet.Range(excelRange)
            Dim dataArray(,) As Object
            dataArray = dataRange.Value

            'get the array specs
            Dim dataArrayRow As Short
            Dim dataArrayCol As Short
            dataArrayRow = dataArray.GetUpperBound(0)
            dataArrayCol = dataArray.GetUpperBound(1)

            'create variables for expression loops
            Dim textString As String = "Values a" + vbCrLf
            Dim rowCounter As Short
            Dim colCounter As Short

            For rowCounter = 1 To dataArrayRow
                For colCounter = 1 To dataArrayCol
                    textString = String.Concat(textString, 
dataArray(rowCounter, colCounter).ToString() + "   ")
                Next
                textString = textString + vbCrLf
            Next


            txtResults.Text = textString
            xlApp.Quit()
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
How can I detect and handle merged cells when retrieving data from an excel
workbook? TIA!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I sort an Excel Doc containing merged & non-merged cells? KellyH Excel Discussion (Misc queries) 11 June 10th 08 04:12 AM
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
Merged Cells in Worksheet, Test for [email protected] Excel Discussion (Misc queries) 2 September 28th 06 05:09 PM
how do i link merged cells to a merged cell in another worksheet. ibbm Excel Worksheet Functions 3 April 27th 06 11:40 PM
Sorting merged cellsHow do I sort merged cells not identically siz Laval Excel Worksheet Functions 1 November 3rd 04 09:40 PM


All times are GMT +1. The time now is 09:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"