// Import the IronXL library to access its functionalityusing IronXL;static voidMain(string[] args){ // Access Excel file WorkBook wb = WorkBook.Load("sample.xlsx"); // Access WorkSheet of Excel file WorkSheet ws = wb.GetWorkSheet("Sheet1"); // Get a specific cell value, convert it to a string, and print it string a = ws["A5"].Value.ToString();Console.WriteLine("Getting Single Value:\n\n Value of Cell A5: {0}", a);Console.WriteLine("\nGetting Many Cells Value using Loop:\n"); // Get multiple cell values using range function and iterate through them foreach (var cell in ws["B2:B10"]) {Console.WriteLine(" Value is: {0}", cell.Text); }Console.ReadKey(); // Pause the console to view output}
// Import the IronXL library to access its functionality
using IronXL;
static void Main(string[] args)
{
// Access Excel file
WorkBook wb = WorkBook.Load("sample.xlsx");
// Access WorkSheet of Excel file
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Get a specific cell value, convert it to a string, and print it
string a = ws["A5"].Value.ToString();
Console.WriteLine("Getting Single Value:\n\n Value of Cell A5: {0}", a);
Console.WriteLine("\nGetting Many Cells Value using Loop:\n");
// Get multiple cell values using range function and iterate through them
foreach (var cell in ws["B2:B10"])
{
Console.WriteLine(" Value is: {0}", cell.Text);
}
Console.ReadKey(); // Pause the console to view output
}
' Import the IronXL library to access its functionalityImportsMicrosoft.VisualBasicImportsIronXLShared Sub Main(ByVal args() AsString) ' Access Excel file Dim wb AsWorkBook = WorkBook.Load("sample.xlsx") ' Access WorkSheet of Excel file Dim ws AsWorkSheet = wb.GetWorkSheet("Sheet1") ' Get a specific cell value, convert it to a string, and print it Dim a AsString = ws("A5").Value.ToString()Console.WriteLine("Getting Single Value:" & vbLf & vbLf & " Value of Cell A5: {0}", a)Console.WriteLine(vbLf & "Getting Many Cells Value using Loop:" & vbLf) ' Get multiple cell values using range function and iterate through them For Each cell In ws("B2:B10")Console.WriteLine(" Value is: {0}", cell.Text) Next cellConsole.ReadKey() ' Pause the console to view outputEnd Sub
' Import the IronXL library to access its functionality
Imports Microsoft.VisualBasic
Imports IronXL
Shared Sub Main(ByVal args() As String)
' Access Excel file
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
' Access WorkSheet of Excel file
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
' Get a specific cell value, convert it to a string, and print it
Dim a As String = ws("A5").Value.ToString()
Console.WriteLine("Getting Single Value:" & vbLf & vbLf & " Value of Cell A5: {0}", a)
Console.WriteLine(vbLf & "Getting Many Cells Value using Loop:" & vbLf)
' Get multiple cell values using range function and iterate through them
For Each cell In ws("B2:B10")
Console.WriteLine(" Value is: {0}", cell.Text)
Next cell
Console.ReadKey() ' Pause the console to view output
End Sub
' Access WorkBook and WorkSheetDim wb AsWorkBook = WorkBook.Load("sample.xlsx")Dim ws AsWorkSheet = wb.GetWorkSheet("Sheet1")' Convert workbook to DataSetDim ds AsDataSet = wb.ToDataSet()' Convert worksheet to DataTableDim dt AsDataTable = ws.ToDataTable(True)
' Access WorkBook and WorkSheet
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
' Convert workbook to DataSet
Dim ds As DataSet = wb.ToDataSet()
' Convert worksheet to DataTable
Dim dt As DataTable = ws.ToDataTable(True)
// Import the IronXL libraryusing IronXL;static voidMain(string[] args){ // Create a new WorkBook WorkBook wb = WorkBook.Create(); // Create a new WorkSheet in the workbook WorkSheet ws = wb.CreateWorkSheet("sheet1"); // Insert data into cells ws["A1"].Value = "New Value A1"; ws["B2"].Value = "New Value B2"; // Save the newly created Excel file wb.SaveAs("NewExcelFile.xlsx");}
// Import the IronXL library
using IronXL;
static void Main(string[] args)
{
// Create a new WorkBook
WorkBook wb = WorkBook.Create();
// Create a new WorkSheet in the workbook
WorkSheet ws = wb.CreateWorkSheet("sheet1");
// Insert data into cells
ws["A1"].Value = "New Value A1";
ws["B2"].Value = "New Value B2";
// Save the newly created Excel file
wb.SaveAs("NewExcelFile.xlsx");
}
' Import the IronXL libraryImportsIronXLShared Sub Main(ByVal args() AsString) ' Create a new WorkBook Dim wb AsWorkBook = WorkBook.Create() ' Create a new WorkSheet in the workbook Dim ws AsWorkSheet = wb.CreateWorkSheet("sheet1") ' Insert data into cells ws("A1").Value = "New Value A1" ws("B2").Value = "New Value B2" ' Save the newly created Excel file wb.SaveAs("NewExcelFile.xlsx")End Sub
' Import the IronXL library
Imports IronXL
Shared Sub Main(ByVal args() As String)
' Create a new WorkBook
Dim wb As WorkBook = WorkBook.Create()
' Create a new WorkSheet in the workbook
Dim ws As WorkSheet = wb.CreateWorkSheet("sheet1")
' Insert data into cells
ws("A1").Value = "New Value A1"
ws("B2").Value = "New Value B2"
' Save the newly created Excel file
wb.SaveAs("NewExcelFile.xlsx")
End Sub
以上代码将创建一个名为New Value B2。 通过这种设置,您可以根据需要以相同的方式插入数据。
// Import the IronXL libraryusing IronXL;static voidMain(string[] args){ // Access the WorkBook and WorkSheet WorkBook wb = WorkBook.Load("sample.xlsx"); WorkSheet ws = wb.GetWorkSheet("Sheet1"); // Update A3 cell value ws["A3"].Value = "New Value of A3"; // Save the updated Excel file wb.SaveAs("sample.xlsx");}
// Import the IronXL library
using IronXL;
static void Main(string[] args)
{
// Access the WorkBook and WorkSheet
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Update A3 cell value
ws["A3"].Value = "New Value of A3";
// Save the updated Excel file
wb.SaveAs("sample.xlsx");
}
' Import the IronXL libraryImportsIronXLShared Sub Main(ByVal args() AsString) ' Access the WorkBook and WorkSheet Dim wb AsWorkBook = WorkBook.Load("sample.xlsx") Dim ws AsWorkSheet = wb.GetWorkSheet("Sheet1") ' Update A3 cell value ws("A3").Value = "New Value of A3" ' Save the updated Excel file wb.SaveAs("sample.xlsx")End Sub
' Import the IronXL library
Imports IronXL
Shared Sub Main(ByVal args() As String)
' Access the WorkBook and WorkSheet
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
' Update A3 cell value
ws("A3").Value = "New Value of A3"
' Save the updated Excel file
wb.SaveAs("sample.xlsx")
End Sub
// Import the IronXL libraryusing IronXL;static voidMain(string[] args){ // Access the WorkBook and WorkSheet WorkBook wb = WorkBook.Load("sample.xlsx"); WorkSheet ws = wb.GetWorkSheet("Sheet1"); // Specify a range from B5 to G5 and replace "Normal" value with "Good" ws["B5:G5"].Replace("Normal", "Good"); // Save the updated Excel file wb.SaveAs("sample.xlsx");}
// Import the IronXL library
using IronXL;
static void Main(string[] args)
{
// Access the WorkBook and WorkSheet
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Specify a range from B5 to G5 and replace "Normal" value with "Good"
ws["B5:G5"].Replace("Normal", "Good");
// Save the updated Excel file
wb.SaveAs("sample.xlsx");
}
' Import the IronXL libraryImportsIronXLShared Sub Main(ByVal args() AsString) ' Access the WorkBook and WorkSheet Dim wb AsWorkBook = WorkBook.Load("sample.xlsx") Dim ws AsWorkSheet = wb.GetWorkSheet("Sheet1") ' Specify a range from B5 to G5 and replace "Normal" value with "Good" ws("B5:G5").Replace("Normal", "Good") ' Save the updated Excel file wb.SaveAs("sample.xlsx")End Sub
' Import the IronXL library
Imports IronXL
Shared Sub Main(ByVal args() As String)
' Access the WorkBook and WorkSheet
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
' Specify a range from B5 to G5 and replace "Normal" value with "Good"
ws("B5:G5").Replace("Normal", "Good")
' Save the updated Excel file
wb.SaveAs("sample.xlsx")
End Sub
// Import the IronXL libraryusing IronXL;static voidMain(string[] args){ // Access the WorkBook and WorkSheet WorkBook wb = WorkBook.Load("sample.xlsx"); WorkSheet ws = wb.GetWorkSheet("Sheet1"); // Remove the row number 2 ws.Rows[2].Remove(); // Save the updated Excel file wb.SaveAs("sample.xlsx");}
// Import the IronXL library
using IronXL;
static void Main(string[] args)
{
// Access the WorkBook and WorkSheet
WorkBook wb = WorkBook.Load("sample.xlsx");
WorkSheet ws = wb.GetWorkSheet("Sheet1");
// Remove the row number 2
ws.Rows[2].Remove();
// Save the updated Excel file
wb.SaveAs("sample.xlsx");
}
' Import the IronXL libraryImportsIronXLSubMain(ByVal args() AsString) ' Access the WorkBook and WorkSheet Dim wb AsWorkBook = WorkBook.Load("sample.xlsx") Dim ws AsWorkSheet = wb.GetWorkSheet("Sheet1") ' Remove the row number 2 ws.Rows(2).Remove() ' Save the updated Excel file wb.SaveAs("sample.xlsx")End Sub
' Import the IronXL library
Imports IronXL
Sub Main(ByVal args() As String)
' Access the WorkBook and WorkSheet
Dim wb As WorkBook = WorkBook.Load("sample.xlsx")
Dim ws As WorkSheet = wb.GetWorkSheet("Sheet1")
' Remove the row number 2
ws.Rows(2).Remove()
' Save the updated Excel file
wb.SaveAs("sample.xlsx")
End Sub