ByteScout Spreadsheet SDK - VB.NET - Convert XML to XLS - ByteScout

ByteScout Spreadsheet SDK – VB.NET – Convert XML to XLS

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – VB.NET – Convert XML to XLS

How to convert XML to XLS in VB.NET with ByteScout Spreadsheet SDK

The tutorial shows how to convert XML to XLS in VB.NET

Source code documentation samples provide quick and easy way to add a required functionality into your application. What is ByteScout Spreadsheet SDK? It is the SDK to create, read, modify and calculate spreadsheets. Formula calculations are supported, import and export to and from JSON, CSV, XML, databases, arrays. It can help you to convert XML to XLS in your VB.NET application.

This rich sample source code in VB.NET for ByteScout Spreadsheet SDK includes the number of functions and options you should do calling the API to convert XML to XLS. In order to implement the functionality, you should copy and paste this code for VB.NET below into your code editor with your app, compile and run your application. Use of ByteScout Spreadsheet SDK in VB.NET is also explained in the documentation included along with the product.

ByteScout Spreadsheet SDK free trial version is available on our website. VB.NET and other programming languages are supported.

Try ByteScout Spreadsheet SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

Imports System.Drawing Imports System.Xml Imports Bytescout.Spreadsheet Imports Bytescout.Spreadsheet.Constants Module Module1 Sub Main() ' Load XML document Dim xmlDocument = New XmlDocument() xmlDocument.Load("sample.xml") ' Read columns information from XML data Dim columns = New List(Of String)() Dim columnNodeList = xmlDocument.SelectNodes("/Report/Columns/Column") For Each node As XmlNode In columnNodeList columns.Add(node.Attributes("Name").Value) Next ' Read row nodes from XML data Dim rowNodeList = xmlDocument.SelectNodes("/Report/ReportData") ' Create new spreadsheet Dim spreadsheet = New Spreadsheet() spreadsheet.RegistrationName = "demo" spreadsheet.RegistrationKey = "demo" ' Add worksheet Dim worksheet = spreadsheet.Worksheets.Add() ' Add column headers For c As Integer = 0 To columns.Count - 1 worksheet(0, c).Value = columns(c) worksheet(0, c).FillPattern = PatternStyle.Solid worksheet(0, c).FillPatternForeColor = Color.LightGray Next Dim rowIndex = 1 ' Add rows For Each rowNode As XmlNode In rowNodeList ' Get cell values from XML data For Each childNode As XmlNode In rowNode.ChildNodes ' Get cell info from XML data Dim columnIndex = columns.IndexOf(childNode.Name) Dim cellValue = childNode.InnerText Dim cell = worksheet(rowIndex, columnIndex) ' Set cell text Cell.Value = cellValue ' Set cell text alignment cell.AlignmentHorizontal = IIf(columnIndex = 0, AlignmentHorizontal.Left, AlignmentHorizontal.Right) Next ' Add the row to the table rowIndex = rowIndex + 1 Next ' Fit columns width to cell data For c As Integer = 0 To columns.Count - 1 worksheet.Columns(c).AutoFit() Next ' Save document to file spreadsheet.SaveAsXLS("result.xls") ' Cleanup spreadsheet.Dispose() ' Open document in Excel Process.Start("result.xls") End Sub End Module

Try ByteScout Spreadsheet SDK today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)



Get 60 Day Free Trial or Visit ByteScout Spreadsheet SDK Home Page

Explore ByteScout Spreadsheet SDK Documentation

Get ByteScout Spreadsheet SDK Free Training


Get Your Free API Key

Explore Web API Documentation