Corrupted EXCEL file
hadrizi opened this issue · 7 comments
I am using libxlsxwriter to make DOS txt parser.
But when i tried to build an application for Windows it compiled with no errors, and when I opened my excel file I got this message
Excel could not open file.xlsx because some content is unreadable. Do you want to open and repair this workbook.
so most of my data was missed.
So i tried to write small example code and chek if problem appears again and it does.
I am using Visual Studio 2017, libxlsxwriter was built according to this guide, my OS is Windows 10
Here is small code i tried to compile:
#include "xlsxwriter.h"
struct header
{
char name[256];
};
struct header hd = { "hey" };
int main() {
lxw_workbook *workbook = workbook_new("hello_world.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
lxw_row_t r = 0;
lxw_col_t c = 0;
worksheet_write_string(worksheet, r, c, hd.name, NULL);
return workbook_close(workbook);;
}
P.S here is the code I compiled on Ubuntu 18.04. Sorry it is in Russian, but there is only one code file in src folder.
So i tried to write small example code and chek if problem appears again and it does.
That source file doesn't have any issues:
I also ran the tArass file with the Readme.md file as input and that worked fine as well:
The issue is probably that you are processing a file that isn't UTF-8 encoded. All strings passed to libxlsxwriter (and Excel) must be UTF8 encoded. Do you think that may be your issue?
@jmcnamara hm, this is strange I reloaded my PC and smaller code started to work. But tArass still doesn't work.
Here is file I'm parsing.
and it seems that file is UTF-8 encoded
А строки ""Выполняемая команда" и т.п. в worksheet_merge_range ты точно в UTF-8 передаешь? Файл xlsx на выходе прикрепи, его можно распаковать и посмотреть, что там не нравится Excel
А строки ""Выполняемая команда" и т.п. в worksheet_merge_range ты точно в UTF-8 передаешь?
Файл xlsx на выходе прикрепи, его можно распаковать и посмотреть, что там не нравится Excel
а вот сам xlsx файл
Строки ты передаешь в Win-1251, поэтому файл на выходе битый. Надо передавать в UTF-8. Я не знаю как это сделать в VS (не программист на С), возможно какой-то параметр сборки проекта. Либо использовать функции перекодирования MultiByteToWideChar/WideCharToMultiByte. Замени временно все русские строки на пустые либо транслитерируй их и увидишь, что дело в этом
Строки ты передаешь в Win-1251, поэтому файл на выходе битый.
Да, так оно и есть. Я просто поменял кодировку исходника, собрал и все сработало.
@RaFaeL-NN Спасибо за помощь