Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure to use this plugin in my Ionic 5 app to view excel from assets #20

Closed
skyleguy opened this issue Mar 12, 2021 · 11 comments
Closed

Comments

@skyleguy
Copy link

skyleguy commented Mar 12, 2021

in my /assets i have test.xlsx and I am attempting to use this plugin like so:

After running:

npm install @ionic-native/preview-any-file --save
ionic cordova plugin add cordova-plugin-preview-any-file --save

/* app.module.ts */
import { PreviewAnyFile } from '@ionic-native/preview-any-file/ngx';
...
providers: [PreviewAnyFile]
...

/* test.component.ts */
constructor(private previewAnyFile: PreviewAnyFile) {}

public viewFile(): void {
      this.previewAnyFile
      .preview('/assets/test.xlsx')
      .then((res): any => {
        console.log(res);
      })
      .catch((err: any): any => {
        console.log(err);
      });
}

but it claims that the url is not supported and i even get a warning to use previewAsset as preview is deprecated. However when i try to use preivewAsset it says the method does not exist. Any help with this? I found this plugin from the ionic documentation at: https://ionicframework.com/docs/native/preview-any-file

@mostafa-mansour1
Copy link
Owner

Unfortunately, my pull request for update ionic native plugin didn't process till now,

So if you need to use the plugin, you have to use it without the ionic native interface,

here is how to use it directly

  (<any>window).PreviewAnyFile.previewAsset(
        win => console.log("open status",win),
        error => console.error("open failed", error),
        '/assets/test.xlsx'
    );

@mostafa-mansour1
Copy link
Owner

also if you really need the ionic interface wrapper, you have to update the folder in node_moduls with this folder in this comment

#14 (comment)

@skyleguy
Copy link
Author

Thank you! I did see your PR to the ionic native repo but I'm pretty unfamiliar with the timing here, do you have an estimate on when you think that might make it into an available version?

@mostafa-mansour1
Copy link
Owner

mostafa-mansour1 commented Mar 12, 2021 via email

@skyleguy
Copy link
Author

thank you for the speedy replies. After using the code snippet you supplied and also replacing my preview-any-file folder you supplied in the other comment i am still not seeing the preview show up. I know its working because i accidentally spelled my file name wrong and your plugin printed a warning about the file not being at the specified location/couldnt find the file. but now that its typed correctly im getting no error or success showing up. any thoughts?

@mostafa-mansour1
Copy link
Owner

First of all, try to remove the plugin, then build the app again, then add the plugin again, and build again

that to sure all files went to the correct place, after that try to run from Xcode or android studio ( depend on your app)

then click on your link and check the debugging, if there is an error it may appear

If you failed, please WhatsApp me to go in details https://wa.me/971524988466

@skyleguy
Copy link
Author

skyleguy commented Mar 12, 2021

hey, took a little while to generate my application but i've made a bare bones app to try and recreate my issue seen in the main app i use. https://github.com/skyleguy/cordova-preview-any-file-test all it does is wait 5 seconds from app start and then try to view an xlsx file in the assets folder called 'Budgeting.xlsx'. nothing seems to happen even though the call to previewAsset is firing. You 'should' be able to just run npm i and then npm run build:ios to open the app in xcode

@mostafa-mansour1
Copy link
Owner

mostafa-mansour1 commented Mar 12, 2021 via email

@skyleguy
Copy link
Author

skyleguy commented Mar 13, 2021

honestly i wouldn't worry about it too much for my sake, i just got a version working with excel files using the previewBase64 method (which is what we'd probably actually be going with) and its pretty cool! the export option already shows the excel app as an option to open/save which lets me download an excel file from my app, open in the excel app, and save to my companies one drive 👍 Is there a way to modify the preview? on my iPhone 12 Pro the area above the grey header bar looks a bit off as the grey just stops and white fills the notch-area. would be nice if the grey continued all the way into the safe area. its hard to tell from this picture but the export options in the bottom left are also a little hard to click due to the curvature of the phone. Overall very cool thank you for this!

It is rather annoying having to make a network call to retrieve my excel file, convert to base 64, and then previewBase64, does the previewPath method take headers as an option so i can hit an endpoint that takes authorization? That would be nice to use if it stops me from having to base64 my ArrayBuffer response.

Here is the image of my iphone that i referenced above, you can see the area where the battery icon is is completely white and looks a little funky. Picture does not show at all the export icon issue i mentioned though: _______________________________

Screen Shot 2021-03-12 at 7 18 42 PM

@mostafa-mansour1
Copy link
Owner

mostafa-mansour1 commented Mar 13, 2021 via email

@skyleguy
Copy link
Author

skyleguy commented Mar 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants