Apple does not provide a method to export iMessages/text messages automatically. In order to export iMessages from an iPhone, you will need to utilize a third-party program that allows you to export via a Mac or a PC.
To obtain the maximum number of text messages you want to save, make sure your phone has “forever” set for how long you want to save messages. You can set this to whatever you like in order to achieve a conversation baseline. This could be a month or up to forever, depending on your needs.
See this for details on how to set this on your iPhone: How to Change How Long You Store Text Message History on iPhone or iPad - YouTube
We've partnered with iMazing to provide you with the ability to export your messages with their software.
Download iMazing ? iMazing Free Downloads for PC and Mac versions of their software.
Use this Key to unlock the software: imz3b3663159bae8c04
This tool is capable of exporting multiple file formats. The format that we support is XLSX file format. Be sure to select this format when exporting which will say "Export to Excel".
Also, these great steps from iMazing's support section are really helpful -> Transfer iPhone messages (SMS), MMS, and iMessages to your computer. Be sure to choose the export option in the bottom that says "Export to Excel"
In this video, when exporting, ensure to click the "Export to Excel" option instead of the "Export to Text" option that is shown in the video :)