Reputation: 11
I am developing excel addin in flutter web. I have this function in project that is used to save current excel file and open new workbook and import sheets from my template file into that newly created file.
//save create and import
function saveCreateAndImportWorkbookFromAssets() {
// Path to your asset Excel file
const filePath = 'assets/files/template.xlsx';
// Firstly, save the current workbook
Excel.run(function(context) {
// Save the current workbook
context.workbook.save(Excel.SaveBehavior.prompt);
// Run the batch operation
return context.sync()
.then(function() {
// Now that the workbook is saved, proceed to create a new workbook
// Fetch the file
return fetch(filePath);
})
.then(response => response.blob())
.then(blob => {
// Use FileReader to read the file as a data URL
const reader = new FileReader();
reader.onload = function(event) {
// Extract the base64 string
const base64Index = event.target.result.indexOf("base64,") + "base64,".length;
const base64String = event.target.result.substring(base64Index);
// Create a new workbook with the base64 string
Excel.createWorkbook(base64String).then(function() {
console.log("New workbook created and loaded with the sheets from the asset file.");
}).catch(function(error) {
console.error("Error creating new workbook:", error);
});
};
// Read the fetched blob as a data URL
reader.readAsDataURL(blob);
})
.catch(error => {
console.error("Error fetching the asset Excel file:", error);
});
}).catch(function(error) {
console.error("Error saving the current workbook:", error);
});
};
This function works perfectly fine when i test this on my localhost but when i publish this to firebase it does not work i have other feature related to office js library but all other things are working just fine. Means communication between my app and office js is working except this single function.
I am using this office js api method: https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-workbooks#create-a-workbook I am side loading addin using this: https://learn.microsoft.com/en-us/office/dev/add-ins/testing/create-a-network-shared-folder-catalog-for-task-pane-and-content-add-ins
i am trying to import excel sheet from a template using office js insertWorksheetsFromBase64 method its working in localhost:3000 port and failing on publishing to firebase/aws.
To replicate issue i have created a repo: https://github.com/MalikSamiAwan/excel_addin_proof_of_concept
only need to do only following changes to make this work: i have updated these two file i have customise package code according to my requirements files attached to the repo[https://github.com/MalikSamiAwan/excel_addin_proof_of_concept] inside this directory updatedcustomfiletobereplaced: file1 path: /.pub-cache/hosted/pub.dev/officejs-0.4.0/lib/src/office_interops/excel_js_impl.dart file2 path: /.pub-cache/hosted/pub.dev/officejs-0.4.0/lib/src/office/excel.dart
Setup Local Addin:
Addin Manifest file attached (filename: sheetmanage_test1 copy.xml) repo[https://github.com/MalikSamiAwan/excel_addin_proof_of_concept] inside this directory updatedcustomfiletobereplaced:
Step1: For testing this feature in local host we need to side load this addin manifest: sheetmanage_test1.xml file attached Step2: Start flutter web: flutter run -d chrome --web-port 3000 And than we can replicate this issueenter image description here
Upvotes: 0
Views: 162
Reputation: 11
The issue was due to file path. I have to place template file inside flutter web directory instead of assets directory.
Upvotes: 1