I want Use X++ code to open the Excel file, insert data and save it to the specified location,The examples I found are all adding a new excel, as shown below:
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class RunnableClass1
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
FilePath templateFile;
Filename fileName;
CustTable custTable;
MemoryStream memoryStream = new MemoryStream();
using (var package = new ExcelPackage(memoryStream))
{
var currentRow = 1;
var worksheets = package.get_Workbook().get_Worksheets();
var CustTableWorksheet = worksheets.add('excel');
var cells = CustTableWorksheet.get_Cells();
OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
System.String value = "Account Number";
cell.set_Value(value);
cell = null;
value = "Currency";
cell = cells.get_Item(currentRow, 2);
cell.set_Value(value);
while select CustTable
{
currentRow ++;
cell = null;
cell = cells.get_Item(currentRow, 1);
cell.set_Value(CustTable.AccountNum);
cell = null;
cell = cells.get_Item(currentRow, 2);
cell.set_Value(CustTable.Currency);
}
package.Save();
file::SendFileToUser(memoryStream,'textcexcel');
}
}
}