In Stata 14, this code works:
but this code doesn't, and returns an r(691) error message that says "could not write to file."
The only difference is that the sheet name is 31 characters in the first piece of code, and 32 characters in the second code sample. Sheet names in Excel are capped at 31 characters, but the current error message is highly uninformative.
Furthermore, the error message from "export excel" is even less helpful. This code
returns an r(9901) error message that says
I realize this is a symptom of Stata's wider problem with uninformative error messages, but it seems like it would be possible to perform basic validation in "putexcel" and "export excel" that would return an informative error message if the user tried to pass a sheet name of 32+ characters.
I wasn't able to find any discussion of this in Stata's documentation, either, but this is a known, hard limit in the Excel format.
Code:
putexcel set "example.xlsx", sheet("this name is too long for Excel") replace putexcel A1 = (2)
Code:
putexcel set "example.xlsx", sheet("this name is too long for Excel.") replace putexcel A1 = (2)
Furthermore, the error message from "export excel" is even less helpful. This code
Code:
sysuse auto, clear export excel "example.xlsx", sheet("this name is too long for Excel.") replace
Code:
_xlshwritestrcol(): 9901 Stata returned error export_excel_write_file(): - function returned error export_excel_export_file(): - function returned error <istmt>: - function returned error r(9901);
I wasn't able to find any discussion of this in Stata's documentation, either, but this is a known, hard limit in the Excel format.
Comment