Unable to create a usable xlsx file

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
warmly
Posts: 3
Joined: 15 Nov 2024 13:58

Unable to create a usable xlsx file

Post by warmly »

When I create a new xlsx file, it displays as invalid "Excel cannot open the file '.xlsx' because the file format or file extension is not valid.Verify that the file has not been corrupted and that the file extension matches the format of the file." While .docx and .pptx is OK.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Unable to create a usable xlsx file

Post by highend »

And how exactly are you creating this file?
One of my scripts helped you out? Please donate via Paypal

warmly
Posts: 3
Joined: 15 Nov 2024 13:58

Re: Unable to create a usable xlsx file

Post by warmly »

highend wrote: 15 Nov 2024 14:16 And how exactly are you creating this file?
Right-click and select 'New', then choose 'New File', enter "filename.xlsx" in the dialog box, and click 'OK'.

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Unable to create a usable xlsx file

Post by highend »

You are creating a text! file, not an Excel file^^

Open Excel, create a new, empty document, save it as e.g. "Excel document.xlxs" in your
path to XYplorer data folder\NewItems folder.

And then, to create a new Excel file, use the context menu, choose "New Items" and in its submenu choose the "Excel document.xlxs"...
One of my scripts helped you out? Please donate via Paypal

warmly
Posts: 3
Joined: 15 Nov 2024 13:58

Re: Unable to create a usable xlsx file

Post by warmly »

highend wrote: 15 Nov 2024 14:35 You are creating a text! file, not an Excel file^^

Open Excel, create a new, empty document, save it as e.g. "Excel document.xlxs" in your
path to XYplorer data folder\NewItems folder.

And then, to create a new Excel file, use the context menu, choose "New Items" and in its submenu choose the "Excel document.xlxs"...
But I wanna create Excel files in batch directly in XYplore. If it's about creating a few Word documents and PPTs, I just need to enter "File1.docx""File2.pptx" in the dialog box, then I'll get available documents. I hope that creating EXCEL documents in batch can be just as straightforward.

altoclef
Posts: 87
Joined: 12 Oct 2012 18:54
Location: Win10 @100%

Re: Unable to create a usable xlsx file

Post by altoclef »

warmly wrote: 15 Nov 2024 14:26 Right-click and select 'New', then choose 'New File', enter "filename.xlsx" in the dialog box, and click 'OK'.
This dialog creates zero-length files:

NewFiles.png
NewFiles.png (25.06 KiB) Viewed 950 times

Although Windows displays the icons and types based on the file extension, I would argue that they are of no type as they are completely empty.

Contrast this with new blank documents created through the respective apps:

NewDocuments.png
NewDocuments.png (17.85 KiB) Viewed 950 times

which hold document metadata and starter data, such as an empty slide in PowerPoint:

NewPowerPoint.png
NewPowerPoint.png (7.39 KiB) Viewed 950 times

Word and PowerPoint are forgiving and will open an empty document (note that PowerPoint displays such a document differently from a new presentation).

EmptyPowerPoint.png
EmptyPowerPoint.png (8.71 KiB) Viewed 950 times

However, Excel is apparently not able to open an empty document and so you receive the error message that you quoted in your original message.

If you want to create correctly initialised documents, then use the New Items menu that @highend mentioned (or there might be a way to do it using a script but I can't help with that).

(@admin Please could you update the New Files entry in the help to make this clearer?)

highend
Posts: 14571
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Unable to create a usable xlsx file

Post by highend »

While Office files could be created from scratch via vbscript for each file type, copying and renaming is (script-technically) easier...

Code: Select all

    // These files must exist in "<xynewitems>"!
    $templateFiles = <<<>>>
Excel document.xlsx
PowerPoint document.pptx
Word document.docx
    >>>;

    // $default = "a.docx<crlf>b.xlsx<crlf>c.pptx<crlf>d.txt";
    $default = "";
    $files   = input("Enter file name(s) to create...", 2:=$default, 3:="m", 5:=600, 6:=400);


    // Check which template files really exist
    $existingTemplateFiles    = "";
    $nonExistingTemplateFiles = "";
    foreach($templateFile, $templateFiles, <crlf>, "e") {
        $file = <xynewitems> . "\" . $templateFile;
        $ext  = gpc($file, "ext");
        if (exists($file) == 1) { $existingTemplateFiles    .= $ext . "|" . $templateFile . <crlf>; }
        else                    { $nonExistingTemplateFiles .= $ext . "|" . $templateFile . <crlf>; }
    }

    setting "BackgroundFileOps", 0;

    // All files can be created, make exceptions for standard Office files: doc(x), ppt(x), xls(x)
    $notCreated = "";
    $officeExts = "|doc|docx|ppt|pptx|xls|xlsx|";
    foreach($file, $files, <crlf>, "e") {
        $ext = gpc($file, "ext");

        // Office file(s)
        if (strpos($officeExts, "|" . $ext . "|") != -1) {
            $matchNonExisting = regexmatches($nonExistingTemplateFiles, "^" . $ext . "\|");
            if ($matchNonExisting) { $notCreated .= $file . <crlf>; continue; }

            // Get the belonging template file, copy it over, rename it
            $templateFile = regexmatches($existingTemplateFiles, "^" . $ext . "\|.+?$");
            $templateFile = <xynewitems> . "\" . gettoken($templateFile, 2, "|");

            $dstFile = <curpath> . "\" . $file;
            if (exists($dstFile) != 1) { copyitem $templateFile, $dstFile; }

        // All other file types
        } else {
            new(<curpath> . "\" . $file, "file");
        }
    }
    if ($notCreated) {
        $msg  = "NOT created, template file does not exist!";
        $msg .= <crlf> . strrepeat("=", strlen($msg)) . <crlf>;
        text  $msg . $notCreated;
    }
One of my scripts helped you out? Please donate via Paypal

Post Reply