web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Converting xls to csv format through batch job.

(0) ShareShare
ReportReport
Posted on by

Hi,

I developed a class to convert xls format to csv. Manually it's executing but error in executing batch job.

Kindly help me in finding mistake in my code.

public void run()
{
Tri_EPaymentReturnTransaction ePaymentReturnTrans;
Tri_ImportTrial ImpTrial;

Name code;
Description Desrc;
int int1;
#File
CommaTextIo commaTextIo;
FileIOPermission permission;
container containFromRead;
int x;
int cols;
int record = 0;


int iCounter = 0;

#File

container readCon, name;
counter icount,inserted;
str checknull,a, extension, ExtFileName;
FileName fileName;
CommaIO csvFile;
int j = 0, i = 0, filecount, DelCnt = 0, filecountDel;
Tri_MessageType MessageType;
System.String[] files, filesDel;
Filename namefile, namefileDel;

SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row = 1;
Tri_ImportTrial importTrial;
FileIoPermission perm;

Tri_EPaymentReturnTransaction ePaymRetTrans;
BankParameters bankParm;

str filename1; //=@"C:\csv\";
#File
#Aif


application = SysExcelApplication::construct();
workbooks = application.workbooks();

select bankParm;
perm = new FileIoPermission(bankParm.Tri_ReturnSharedFolderPath,#io_read);
perm.assert();
if(WinAPIserver::pathExists(bankParm.Tri_ReturnSharedFolderPath))
{
files = System.IO.Directory::GetFiles(bankParm.Tri_ReturnSharedFolderPath);
filecount = files.get_Length();

for(i=0; i < filecount; i++)
{
namefile = files.get_Item(i);
name = fileNameSplit(namefile);
extension = conPeek(name,3);
ExtFileName = conPeek(name,2);
filename1 = @"C:\csv\" + ExtFileName;
if(extension == ".xls")
{
try
{
workbooks.open(namefile);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}

workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();

workbook.saveAs(filename1,6);

workbook.close(false, namefile);
application.quit();

}
}
}

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    If you look at documentation of SysExcelApplication class, for example, you'll see that it runs on client. When you run something in batch, it runs completely on a batch server and there is no client to execute client code. Therefore you can't use this code in batch.

    Either you give up running it in batch, or you'll change your implementation.

  • Community Member Profile Picture
    on at

    Hi Martin,

    I understand that SysExcelApplication class cannot execute over server, but is there any alternate solution for the same scenario. Because I need to develop the same.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You surely can develop something else if you want.

    For instance, you could use .NET Office Interop libraries to run exactly the same logic, but you must make sure that all necessary Office libraries are installed on your batch server(s).

    Or you could use a completely different API. For instance, if your Excel files are in the new format (Open XML), you can use Open XML SDK.

  • Community Member Profile Picture
    on at

    Can you provide me some code or some link, which could help me in developing the same.

    Would be a huge favor,I am really facing issue with this.

    Thanks.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    A code or link for which of the approaches?

  • Community Member Profile Picture
    on at

    Any thing will be helpful for developing the above scenario.

    where can I find Microsoft.Office.Interop.Excel.dll ?

    how to use this in code.

    That's it sir.

    Thanks.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    There are many articles on internet; it's difficult to pick a few of them if I don't know what you need.

    Try these, for instance:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans