Build and save with a Structure Block
Build what you want to export, then get a Structure Block with /give @s minecraft:structure_block.
Place it near the build, switch it to Save mode, enter a structure name, click Detect, keep Include entities off if you only need blocks, then press Save.