Set cell alignment is easy to implement in VB.NET if you use these source codes below. What is ByteScout Spreadsheet SDK? It is the SDK that can write and read, modify and calculate Excel and CSV spreadsheets. Most popular formulas are supported. You may import or export data to and from CSV, XML, JSON as well as to and from databases, arrays. It can help you to set cell alignment in your VB.NET application.
The SDK samples like this one below explain how to quickly make your application do set cell alignment in VB.NET with the help of ByteScout Spreadsheet SDK. Just copy and paste the code into your VB.NET application’s code and follow the instruction. Test VB.NET sample code examples whether they respond your needs and requirements for the project.
Free trial version of ByteScout Spreadsheet SDK is available on our website. Documentation and source code samples are included.
Imports Bytescout.Spreadsheet Imports System.IO Imports System.Diagnostics Module Module1 Sub Main() ' Open Spreadsheet Dim document As New Spreadsheet() ' Add new worksheet Dim worksheet As Worksheet = document.Workbook.Worksheets.Add("AlignmentDemo") ' Set Values worksheet.Cell("A1").Value = "Name" ' setting centered alignment for the cell worksheet.Cell("A1").AlignmentHorizontal = Bytescout.Spreadsheet.Constants.AlignmentHorizontal.Centered worksheet.Cell("B1").Value = "Full Name" ' setting centered alignment for the cell worksheet.Cell("B1").AlignmentHorizontal = Bytescout.Spreadsheet.Constants.AlignmentHorizontal.Centered worksheet.Cell("A2").Value = "Homer" ' setting justifiedalignment for the cell worksheet.Cell("A2").AlignmentHorizontal = Bytescout.Spreadsheet.Constants.AlignmentHorizontal.Right worksheet.Cell("B2").Value = "Homer Jay Simpson" ' setting justified alignment for the cell worksheet.Cell("B2").AlignmentHorizontal = Bytescout.Spreadsheet.Constants.AlignmentHorizontal.Right ' set columns width worksheet.Columns(0).Width = 300 ' A column worksheet.Columns(1).Width = 400 ' B column ' remove output file if already exists If File.Exists("Output.xls") Then File.Delete("Output.xls") End If ' Save document document.SaveAs("Output.xls") ' Close Spreadsheet document.Close() ' open in default spreadsheets viewer/editor Process.Start("Output.xls") End Sub End Module