Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hola tengo una mi consulta con un boton que dice descargar en excel..todo bien.
pero yo quiero que esa informacion me la muestre en un hoja aparte del mismo archivo... y estoy usando agular como front
este es mi codigo..
Google Translate:
Hello, I have a query with a button that says download in excel...everything is fine.
but I want that information to be shown to me in a separate sheet of the same file... and I am using agular as a front
this is my code..

let existworkBook =  XLSX.readFile('C:\\Archivo_Descargas\\WEGMANSPRODUCTION021624.xlsx');
        //Crear nueva hoja con los datos
        let newWorkSheet = XLSX.utils.json_to_sheet(salesOrderReport, { header: heading , skipHeader : true});

        //Agregar la nueva hoja al libro existente
        XLSX.utils.book_append_sheet(existworkBook, newWorkSheet , this.translationService.getValue('PRODUCT_SALES_REPORT'));


error que me muestra.
Google Translate:
The error it is showing me.

common-error-handler.service.ts:20 Error: Cannot access file C:\Archivo_Descargas\WEGMANSPRODUCTION021624.xlsx
    at read_binary (xlsx.mjs:3234:8)
    at readSync (xlsx.mjs:23811:69)
    at Module.readFileSync (xlsx.mjs:23851:9)
    at SafeSubscriber._next (product-sales-report.component.ts:316:30)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:183:16)
    at (Subscriber.js:122:22)
    at Subscriber._next (Subscriber.js:72:26)
    at (Subscriber.js:49:18)
    at FilterSubscriber._next (filter.js:33:30)
    at (Subscriber.js:49:18)

What I have tried:

Ejecuto el apicativo y me muestra el error mencionado

Google Translate:
I run the application and it shows me the mentioned error
Updated 14-Feb-24 19:30pm
OriginalGriff 15-Feb-24 1:31am    
This is an English language site, and we can only accept and answer questions in that language.
I have run this through Google Translate to produce a probably-good version, but you should check it and make sure it does say what you are actually asking.

1 solution

The error message is pretty clear: the file cannot be opened.

Read the error message carefully: it says that it is trying to read a file "C:\Archivo_Descargas\WEGMANSPRODUCTION021624.xlsx" from Javascript code and cannot access it.

That's probably because Javascript runs on the client browser, not on the server - and has no direct access to the client filesystem for security reasons. If it did, then no file on your computer would be safe from any website!
In addition, websites don't have direct access to write files to client file systems to prevent them loading viruses, trojans, and other malware onto your PC automatically when you visit a site.

To access client files, the user must initiate an upload of the files to the server, where it can then be processed - but web servers generally do not have Office installed, so you will probably have to find a different solution to your problem!
Share this answer
Richard Deeming 15-Feb-24 3:36am    
Technically, client-side code can get limited access to files on the client:
File System API - Web APIs | MDN[^]

But as you say, it can't read and write arbitrary files, for reasons that should be obvious. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900