Giter VIP home page Giter VIP logo

Comments (11)

patrickbrouwers avatar patrickbrouwers commented on June 16, 2024 1

, the broken file has an empty line at the start of the file

That's a known issue of PhpSpreadsheet. You most likely have an empty line or whitespace in front of a <?php opening tag. It could be in any file in your project.

For the allFields() I've released a patch release, that makes it work again.

from laravel-nova-excel.

patrickbrouwers avatar patrickbrouwers commented on June 16, 2024 1

@DanielDarrenJones great! Happy you found it so quickly :)

Yes explicit would for sure be better :)

from laravel-nova-excel.

patrickbrouwers avatar patrickbrouwers commented on June 16, 2024

Can you show your code please. It seems your export hasn't "selected" any fields to be exported.

from laravel-nova-excel.

DanielDarrenJones avatar DanielDarrenJones commented on June 16, 2024

@patrickbrouwers

/**
 * Get the actions available for the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function actions(Request $request)
{
    return [
        (new DownloadExcel)
            ->withHeadings()
            ->allFields(),
    ];
}

EDIT: I have also tried without the withHeadings and AllFields chains and it still isn't working, it also isnt working across different resources

from laravel-nova-excel.

patrickbrouwers avatar patrickbrouwers commented on June 16, 2024

what's in your fields() array ? ->allFields() is supposed to build up a list of fields from there.
Also ->allFields() is the default behaviour, so you can also remove that call :)

from laravel-nova-excel.

DanielDarrenJones avatar DanielDarrenJones commented on June 16, 2024

on the original resource I had it on:

/**
     * Get the fields displayed by the resource.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),
            Text::make('Name', 'name')->sortable(),

            new Panel('Shopify', $this->shopifyFields()),
            new Panel('Amazon', $this->amazonFields()),
            new Panel('Wayfair', $this->wayfairFields()),

            BelongsToMany::make('Orders'),
        ];
    }

    /**
     * Get the shopify fields for the resource.
     *
     * @return array
     */
    protected function shopifyFields()
    {
        return [
            Text::make('Shopify SKU', 'shopify_sku')
                ->sortable()
                ->hideFromIndex(),
            Text::make('Shopify Product ID', 'shopify_product_id')
                ->sortable()
                ->hideFromIndex(),
            Text::make('Shopify Variant ID', 'shopify_variant_id')
                ->sortable()
                ->hideFromIndex(),
            ExternalUrl::make('Edit on Shopify', function () {
                    if ($this->shopify_product_id == null || $this->shopify_product_id == "") {
                        return null;
                    }

                    $link = "https://new-forest-rustic-furniture-ltd.myshopify.com/admin/products/{$this->shopify_product_id}";

                    if ($this->shopify_variant_id != null && $this->shopify_variant_id != "") {
                        $link = $link . "/variants/{$this->shopify_variant_id}";
                    }

                    return $link;
                })
                ->hideFromIndex(),
        ];
    }

    /**
     * Get the amazon fields for the resource.
     *
     * @return array
     */
    protected function amazonFields()
    {
        return [
            Text::make('Amazon ASIN', 'amazon_asin')
                ->sortable()
                ->hideFromIndex(),
            Text::make('Amazon SKU', 'amazon_sku')
                ->sortable()
                ->hideFromIndex(),
            Text::make('Amazon Marketplace ID', 'amazon_marketplace_id')
                ->sortable()
                ->hideFromIndex(),
            ExternalUrl::make('Edit on Amazon', function () {
                    if ($this->amazon_asin == null || $this->amazon_asin == "") {
                        return null;
                    }

                    if ($this->amazon_sku == null || $this->amazon_sku == "") {
                        return null;
                    }

                    $link = "https://catalog-sc.amazon.co.uk/abis/product/DisplayEditProduct?sku={$this->amazon_sku}&asin={$this->amazon_asin}";

                    if ($this->amazon_marketplace_id != null && $this->amazon_marketplace_id != "") {
                        $link = $link . "&marketplaceID=A1F83G8C2ARO7P{$this->amazon_marketplace_id}";
                    }

                    return $link;
                })
                ->hideFromIndex(),
        ];
    }

    /**
     * Get the wayfair fields for the resource.
     *
     * @return array
     */
    protected function wayfairFields()
    {
        return [
            Text::make('Wayfair SKU', 'wayfair_sku')
                ->sortable()
                ->hideFromIndex(),
            ExternalUrl::make('Edit on Wayfair', function () {
                    if ($this->wayfair_sku == null || $this->wayfair_sku == "") {
                        return null;
                    }

                    return "https://partners.wayfair.com/v/product_catalog/manage_product_description/index?skus={$this->wayfair_sku}";
                })
                ->hideFromIndex(),
        ];
    }

but I have simpler models like users which it isn't working on either:

public function fields(Request $request)
    {
        return [
            ID::make()->sortable(),

            Gravatar::make(),

            Text::make('Name')
                ->sortable()
                ->rules('required', 'max:255'),

            Text::make('Email')
                ->sortable()
                ->rules('required', 'email', 'max:254')
                ->creationRules('unique:users,email')
                ->updateRules('unique:users,email,{{resourceId}}'),

            Password::make('Password')
                ->onlyOnForms()
                ->creationRules('required', 'string', 'min:6')
                ->updateRules('nullable', 'string', 'min:6'),
        ];
    }

from laravel-nova-excel.

DanielDarrenJones avatar DanielDarrenJones commented on June 16, 2024

I just changed the users field to use:

public function actions(Request $request)
    {
        return [
            (new DownloadExcel)
                ->withHeadings()
                ->only('name', 'email'),
        ];
    }

but its now giving the following error when opening:
screen shot 2018-10-31 at 10 51 56

from laravel-nova-excel.

patrickbrouwers avatar patrickbrouwers commented on June 16, 2024

Your first problem is due to ->allFields() . allFields in the past referred to exporting all database columns. Removing that, should export all fields visible on the index screen.

For your new problem, how is your file name? It seems something wrong with the extension.

from laravel-nova-excel.

DanielDarrenJones avatar DanielDarrenJones commented on June 16, 2024

screen shot 2018-10-31 at 10 56 21

The exports look fine in their names?

is there a simple all for all DB columns or do I need to specify this on all resources now manually?

from laravel-nova-excel.

DanielDarrenJones avatar DanielDarrenJones commented on June 16, 2024

Weirdly, I can view to contents of the broken exports in text-edit, but the non broken ones are locked and wont show their contents?

Edit: I managed to view in atom instead, the broken file has an empty line at the start of the file, removing it makes excel realise it's a file but still apears broken

from laravel-nova-excel.

DanielDarrenJones avatar DanielDarrenJones commented on June 16, 2024

@patrickbrouwers aha! yeah there was a whitespace in one of my configs, thanks for the tip there!

Also thanks for adding that back, I should probably define the fields explicitly anyway, but it's a nice helper for testing!

from laravel-nova-excel.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.