Issues with export to excel

Issues with export to excel

RA-NovinRA-Novin Posts: 11Questions: 2Answers: 0
edited January 2023 in Free community support

I have a problem in exporting my table data to excel. There is a column in my table that contains string data with a structure similar to yyyy-mm-dd (some data like 1401-09-25). While exporting to excel, it is considered as date and in excel it is considered as date which is too large to be displayed.
Please guide me how to solve the issue.

This question has an accepted answers - jump to answer

Answers

  • RA-NovinRA-Novin Posts: 11Questions: 2Answers: 0


  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    edited January 2023

    https://datatables.net/reference/button/excelHtml5

    check the link above for customization options. You will need to convince Excel that it shouldn't interpret your data as a date. The use of one of the built-in styles might work. If not you would need to prefix your data using "customize" or "exportOptions". The prefix could be some text or maybe just a blank space.

    Many people have asked similar questions in this forum. I suggest you also search the forum for other relevant threads.

    Good luck!

  • RA-NovinRA-Novin Posts: 11Questions: 2Answers: 0

    Dear rf1234

    Thanx for your reply.
    Actually, I can not use some prefixes because that would ruin the data.
    convincing the excel, I already tried all the possibilities that came to my mind, but they did not fix the issue either.
    I'll be grateful if you guide me through the right exportOptions that you mentioned because before posting my question I looked for such a solution but I did not succeed.

    Thanks

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Have you tried "customize"`? That is the way to tell Excel to treat your column like a string.

  • RA-NovinRA-Novin Posts: 11Questions: 2Answers: 0

    Thanx again.
    It seems that customize should be the answer, but since I am absolutely novice, I did not find the right syntax. Could you kindly privide the syntax. Just suppose I want to specify that a column named "mycolumn" is supposed to be of string type. I realy appreciate that.

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    Answer ✓

    I am sorry, but I can't help you to write your code. Fiddling with Excel using "customize" is maximum punishment for a software developer I would say. I mean you need to manipulate Open XML using jQuery for this!

    I shared my code using "customize" many times in this forum. You can search for that and see what you can use from it. Good luck and thank you for your understanding.

  • RA-NovinRA-Novin Posts: 11Questions: 2Answers: 0

    Thank you very much for your kind consideration, I really appreciate it.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Of interest, this is the part of the code that assigns the column width for the created spreadsheet.

    What I'd suggest doing is dumping the document structure in the customize callback and find the part that defines the column width and create a selector for that. Then modify the value as you need.

    Let us know how you get on with it.

    Allan

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    Is this really only about column width? I thought you had a problem that Excel recognizes your field as a date field and hence transforms it instead of leaving it as it is.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Not sure - that's how I read the question, but I might be totally off the base. @RA-Novin perhaps you can clarify for us.

    Allan

  • RA-NovinRA-Novin Posts: 11Questions: 2Answers: 0

    Dear @Allen and Dear @rf1234

    I am very very very sorry for replying this late, honestly, I saw your comments accidentally today.
    In fact my question was not about column width, it was about Excel recognizing my field as a date field and hence transforming it.
    I took @rf1234 suggestion and inserted some prefix to my data and issue was solved. Thanks a lot for it.

Sign In or Register to comment.