jakkku ma
asked on
reading and writing a files in mfc
Reading and Writing CSV Files in MFC code
Files has to open in OpenOffice for the first Data. without closing the OpenOffice ,In background ,program s running and
datas has to saved in the CSV files. close the file and reopened the file .new data s has to updated.But only one data thats is also first data only in CSV file.(only in OpenOffice ,datas are not saved while processing file should in open then close the file and reopened the same file,no datas updated )
code was working in CSV FIle Viewer and Notepad++ while opened while processing ,closed and reopened the same file, data are updated )
Plz help
Files has to open in OpenOffice for the first Data. without closing the OpenOffice ,In background ,program s running and
datas has to saved in the CSV files. close the file and reopened the file .new data s has to updated.But only one data thats is also first data only in CSV file.(only in OpenOffice ,datas are not saved while processing file should in open then close the file and reopened the same file,no datas updated )
code was working in CSV FIle Viewer and Notepad++ while opened while processing ,closed and reopened the same file, data are updated )
Plz help
ASKER
Dialogbased Application.
i had used CFile for open a file(CFile::modeCreate|CFi le::modeRe adWrite,) and Write to enter the datas,it was not updating datas in openOfficeCalc(application to open a document) while file is opened.
i had used CFile for open a file(CFile::modeCreate|CFi
ASKER
Dialogbased Application.
i had used CFile for open a file(CFile::modeCreate|CFi le::modeRe adWrite,) and Write to enter the datas from VC++coding , not updating datas in openOfficeCalc(application to open a document) and open a csv file in microosft excel also updated while file is opened. plz help
HANDLE hFIND = FindFirstFile(output_filen ame.c_str( ), &findData );
if( hFIND == INVALID_HANDLE_VALUE )
{
if (!Open(output_filename.c_s tr(), CFile::modeCreate|CFile::m odeReadWri te |CFile::shareDenyWrite))
{
LOG_INFO << filename << " File unable to open" << ENDLOG;
return;
}
bHeader = true;
}
else
{
CFileStatus status,status2;
status.m_attribute =(BYTE) 0x00;
CFile::SetStatus(output_fi lename.c_s tr(),statu s);
CFile::GetStatus(output_fi lename.c_s tr(),statu s2);
if(status2.m_attribute != 0x00)
{
LOG_INFO << output_filename.c_str() << " File unable to set normal status" << ENDLOG;
return;
}
if (Open(output_filename.c_st r(), CFile::modeWrite |CFile::shareDenyWrite))
{
LOG_INFO<< output_filename.c_str() << " File unable to open" << ENDLOG;
FindClose( hFIND );
return;
}
SeekToEnd();
}
i had used CFile for open a file(CFile::modeCreate|CFi
HANDLE hFIND = FindFirstFile(output_filen
if( hFIND == INVALID_HANDLE_VALUE )
{
if (!Open(output_filename.c_s
{
LOG_INFO << filename << " File unable to open" << ENDLOG;
return;
}
bHeader = true;
}
else
{
CFileStatus status,status2;
status.m_attribute =(BYTE) 0x00;
CFile::SetStatus(output_fi
CFile::GetStatus(output_fi
if(status2.m_attribute != 0x00)
{
LOG_INFO << output_filename.c_str() << " File unable to set normal status" << ENDLOG;
return;
}
if (Open(output_filename.c_st
{
LOG_INFO<< output_filename.c_str() << " File unable to open" << ENDLOG;
FindClose( hFIND );
return;
}
SeekToEnd();
}
was not updating datas in openOfficeCalc(applicationto open a document) while file is opened.
actually that is a problem which you can't solve. if openoffice (or any other program) has opened a file for write, another program cannot open for write again. it even could be that you can't open it for read if the openoffice has opened the file exclusively.
Sara
ASKER
hi
When the microsoft Excel(tried to open CSV file ) is opened,In that file can able to write or not?
When the microsoft Excel(tried to open CSV file ) is opened,In that file can able to write or not?
you can try to open it read-only, if that worked you could write a new file with your mfc app and use automation to open the new file with open office. you also could issue a command that starts openoffice and pass the new file as commandline argument, if the openoffice is already open, the new command should open a new window with the changed document.
another idea is if you recognize that openoffice has opened the file exclusively, that you use automation which forces the openoffice to close the file.
Sara
another idea is if you recognize that openoffice has opened the file exclusively, that you use automation which forces the openoffice to close the file.
Sara
it doesn't make a difference whether it is excel or openoffice. but you could use automation if you find out which program was locking the file.
why is the file opened in excel or openoffice? does it happen intentionally? is it ok if excel or openoffice was terminated by the mfc program?
Sara
why is the file opened in excel or openoffice? does it happen intentionally? is it ok if excel or openoffice was terminated by the mfc program?
Sara
ASKER
While putting Logs and see the datas ,datas are in logs if it is locking somewhere means,but only problem is while writing in the CSV file,the file is opened,so datas are not updated in the opened file even i closed and open again also.
when file is not opened while processing ,after completion if i opened the CSv file all the dats are there.
i want to see after write the first data ,i opend the file and see
user may opened ,closed or reopened ,but new updated datas should be updated
give me example code
when file is not opened while processing ,after completion if i opened the CSv file all the dats are there.
i want to see after write the first data ,i opend the file and see
user may opened ,closed or reopened ,but new updated datas should be updated
give me example code
datas are not updated in the opened file even i closed and open againthat is because open office first saves the current contents and so overwrites the changes you have made.
try the following. open the csv with visual studio. then use your program and change the csv. if you return to visual studio it should tell you, that the file has changed and ask whether you want to reload.
Sara
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
in mfc you could use alternatively CStdioFile class and member functions ReadString and WriteString. it could be an issue that CStdioFile reads and writes wide strings (wchar_t characters coded in UTF16) when the mfc project property for characterset is UNICODE. if that is not wanted you would need to set the characterset to multi-byte such that the strings are char strings (1-byte per character).
note, i don't know what you mean by openoffice and background and what those terms have to do with mfc programming. i don't think that you can use mfc within openoffice.
can you explain better and with samples (screenshots, csv table, existing mfc code, mfc project MDI, SDI, or dialog-based) what your task is?
Sara