Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Spreadsheet .NET
>
Tutorial
> Display Cell Values - Solution II
The following example shows you how to display values from all cells.
C# example
using System; using Independentsoft.Office; using Independentsoft.Office.Spreadsheet; namespace Sample { class Program { static void Main(string[] args) { Workbook book = new Workbook("c:\\test\\input.xlsx"); for(int i=0; i < book.Sheets.Count; i++) { if (book.Sheets[i] is Worksheet) { Worksheet worksheet = (Worksheet)book.Sheets[i]; Console.WriteLine(); Console.WriteLine("Worksheet = " + worksheet.Name); Console.WriteLine("___________________________________________________________________"); for (int j = 0; j < worksheet.Rows.Count; j++) { if (worksheet.Rows[j] != null) { Console.WriteLine(); //write row in new line for (int k = 0; k < worksheet.Rows[j].Cells.Count; k++) { if (worksheet.Rows[j].Cells[k] != null) { Console.Write(worksheet.Rows[j].Cells[k].Value); Console.Write("\t"); } } } } } } Console.Read(); } } }
VB example
Imports System Imports Independentsoft.Office Imports Independentsoft.Office.Spreadsheet Module Module1 Sub Main(ByVal args As String()) Dim book As New Workbook("c:\test\input.xlsx") For i As Integer = 0 To book.Sheets.Count - 1 If TypeOf book.Sheets(i) Is Worksheet Then Dim worksheet As Worksheet = DirectCast(book.Sheets(i), Worksheet) Console.WriteLine() Console.WriteLine("Worksheet = " + worksheet.Name) Console.WriteLine("___________________________________________________________________") For j As Integer = 0 To worksheet.Rows.Count - 1 If worksheet.Rows(j) IsNot Nothing Then Console.WriteLine() 'write row in new line For k As Integer = 0 To worksheet.Rows(j).Cells.Count - 1 If worksheet.Rows(j).Cells(k) IsNot Nothing Then Console.Write(worksheet.Rows(j).Cells(k).Value) Console.Write("" & Chr(9) & "") ' tab End If Next End If Next End If Next Console.Read() End Sub End Module
Need help? Ask our developers:
Name*
Email*
Message*