#1
Hi,
I am currently tryin out trongate and i wanted to process some csv into db.
my approach so far is by using phpspreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)

anyone experienced on using any pakagist library without composer install (psr4 autoloading)?
mind to share some leads?
#2
Hello niceperson,

Thanks for trying out Trongate, I hope you have stared it :)

You can easily use Packagist libraries with Trongate. Note sure what editor you are using, but this example is going to use VS Code with the Trongate VSCode extension installed -> https://marketplace.visualstudio.com/search?term=trongate&target=VSCode&category=All%20categories&sortBy=Relevance (recommend the red icon that will install all you need)

step1 - Create a new app either with the desktop App or download it via GitHub
step2 - Open it up in VS Code
step3 - Right click on the module folder and select 'New Trongate Module' from the dropdown
step4 - Give your module a name, say 'excel' and say yes for a view and name it 'display'
step5 - paste in your browser 'http://localhost/{your_app_name}/excel' changing 'your_app_name' to what you created
step6 - open a terminal in VSCode it should open at the root of your app
step7 - paste in 'composer require phpoffice/phpspreadsheet' and hit enter, composer will grab this library and it's dependencies from Packagist
step8 - open the Excel.php controller and add these lines just after the opening php tags and above the class name

step9 - you can refresh your browser and nothing will happen if there were no errors with the autoload.
step10 - add a method to test it is working. Type 'tgm' just under a new line of the index method to make use of the macros from the Trongate VSCode extension, or paste this:

step11 - browse to 'http://localhost/{your_app_name}/excel/test' and you should find an Excel document in your public folder called 'hello world.xlsx'

I hope that has helped :)

Cheers,
Simon
#3
Hello DaFa,
thanks for the warm welcome.

I've just started when i post this topic. I just want to be sure i could use the speadsheet library beforehand.
Meanwhile I've gone through the documentation and then I've tried out the problem posted here.

I've followed exactly as per you instructions, but to no avail no file created in the public folder.
could it be somthing to do with folder permission?

i'm using XAMPP on macos btw.
everything else seems fine for example the auto-delete-ing of the sql file after running migration (when adding members module).
hence i doubt it was the permission issue.

updated:
I fixed the use namespace, it seems that backslash was missing.
however there's a problem with UConverter'

below is the stack trace from php_error_log


**btw I really love your instruction. really appreciate the help there
#4
Hi niceperson,

To use insert a code block, just open and close like this:
[code]
your code in here...
[/code]
I would also recommend using an online tool to convert HTML entities before you paste them into the code block, as some like the opening php tags will get stripped and your code block will not come out as expected.
I use this one >> https://www.online-toolz.com/tools/text-html-entities-convertor.php

I hope you are enjoying using Trongate? I think you will find that DC will be covering more advanced topics, like this one in the learning zone and as you are new here I do recommend going through all the beginner training >> https://trongate.io/learning-zone and watching some of the already available YouTube videos on David's channel.

oooops my fault - you need to add more backslashes to the namespace (I didn't notice the html-entities-convertor in my previous post) SORRY!

The above autoload should have read like this:


and the test() method also, is missing some HTML tags (not critical, nicer to look at) - above should read like this:

Can you check that you have all the backslashes in the autoload namespace above - it's the only thing I can think of right now that is throwing all those errors with 'UConverter' and #1 to #9 in your error log?

If all goes well you should now have now error, and the 'hello world.xlsx' file should appear in your public folder

Cheers,
Simon
#5
Thanks for the reply above, I did fixed the missing backslash on the namespacing earlier.
the problem/error posted was after a proper namespace had been used.

i think there's a problem with my environment. (i'm using xampp on mac btw)
doing read using phpspreadsheet worked.
the issue is with UConverter as per the log.

I think can close this topic since the original intention was to ask regarding using a library from pakagist (usually via composer)

really hope if anyone out there facing the same issue as mine and managed to solve it can share some tips.
I'm still ahving that UConverter error bust at the moment i just want to read xls (import to DB).
might have trouble if i want to create xls in the future. well, i'll be focusing on my current use case for now

thanks again to DaFa for helping out.

btw, i'm sharing the read snippet just in case
#6
Thanks ?

I discovered why you are getting that UConvertor error, quite simple if you know where to look. It's not a Trongate error, but more to do with your PHP setup. UConvertor is called by StringHelper.php inside the vendor folder.

A little bit of Googling point is directly at 'intl', a php extension, where UConvertor is a method.

So, you need to open your php.ini file and enable it in the 'Dynamic Extensions' area:
Remove the leading semi colon to enable, then restart the Apache server

To this, and you may want to enable the gd extension too, if you want to use the picture upload in Trongate


Cheers,
Simon
#7
Zillion thanks DaFa for helping out.
as suspected, its due to my dev setup plus i cant tell if its due to php ext not enabled issue.

and usually php ext related issue will be flagged during composer install
and for this case, the phpspreadsheet was installed via composer & php on host machine but the trongate project served by xampp.

(sighh.. composer pampered me too much)