Author Topic: Export information to file on Sharepoint or OneDrive  (Read 2579 times)

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
Export information to file on Sharepoint or OneDrive
« on: July 10, 2024, 11:00:56 pm »
Using JavaScript I'm writing some code to export information to an excel file.
This works as long as the file is stored in a local file system.
However, the company is moving to MS365 using Teams, Sharepoint and OneDrive.
So now I would like to store the file on Sharepoint.
I cannot find any suggestions on how to do this.
Not even in the example script libs as provided by "JavaScript - CSV" or "JavaScript - XML".
Any help appreciated.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13287
  • Karma: +557/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Export information to file on Sharepoint or OneDrive
« Reply #1 on: July 10, 2024, 11:19:28 pm »
if you are using the excel API that should be fairly transparant, as long as you pass the correct URL.

If you google "excel vba save file to sharepoint" you should find a lot of answers on stackoverflow that should help you.

Geert

ea0522

  • EA User
  • **
  • Posts: 134
  • Karma: +5/-0
    • View Profile
Re: Export information to file on Sharepoint or OneDrive
« Reply #2 on: July 10, 2024, 11:58:29 pm »
Sorry, but that search didn't find any usable results.

For completeness I included a summarized version of my code at the end of this post.

The code checks whether the filename provided exists.
If not, it generates a new Excel workbook, saves it and tries to move it to the filename provided.
The newly generated filename is determined by the Excel application and set to the default location where it stores all new files.
In some cases, this is a location on the "C:\" drive which works ok, in other cases it is a location on my personal OneDrive which doesn't work...

In my OneDrive environment, the value of strExcelWorkBookFullName is set to "https://<mycompany>.sharepoint.com/personal/<user>/Documents/Documenten/Map1.xlsx".
As this is a generated filename, I take it is correct.
The GetFile() method however cannot find the file.
Could this be one of the differences between VBS and JavaScript?

Code: [Select]
/**
 * Check theExcelFileName and create new file when the file does not exist
 */
function EXCELWCheckExcelFileName( theExcelFileName ) /* : string */
{

let strExcelFileName = theExcelFileName;
var fileSystemObject = new COMObject( "Scripting.FileSystemObject" );
if ( fileSystemObject.FileExists( strExcelFileName ) ) {
return strExcelFileName;
} else {
// If the file does not exist, then create new one
objExcelWorkBook = objExcelApplication.Workbooks.Add();
if ( objExcelWorkBook != null ) {
// If the file added, then save it
objExcelWorkBook.Save( true );
let strExcelWorkBookFullName = objExcelWorkBook.FullName;
// Close the newly added objExcelWorkBook to move the file
objExcelWorkBook.Close();
objExcelWorkBook = null;

// Check filesystem whether file exists
let objExcelFile = fileSystemObject.GetFile( strExcelWorkBookFullName ); // THIS GetFile METHOD RETURNS NULL
objExcelFile.Move( strExcelFileName );
} else {
return null;
}
}

fileSystemObject = null;
return strExcelFileName;
}