|
|
The file pointer gets updated automatically on a read or write operation. The next write to the same file will be positioned after the first write's data.
|
|
|
|
|
Rakesh5 wrote: CFile::modeCreate
You are recreating the file each time with new content using that flag.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
After you open the file, use the SeekToEnd function:
myfile.Open("example.xls",CFile::modeCreate|CFile::modeWrite, NULL);
myfile.SeekToEnd();
myfile.Write(sUserID,sUserID.GetLength());
I can't say that I've ever seen anyone use CFile to write to an excel file, so I'm not sure how you're accomplishing that. Most people would write the data to a .csv file, which can then be opened in excel. Each cell data on the same line would be separated by a comma, with a CR/LF pair at the end of that line.
I don't think you're actually creating a true .xls file - it's most likely just a text file, but with the .xls extension, excel may be able to open it.
Be aware that just because you name a file with .xls as an extension, it's not really an Excel file.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
hi,
thanks alot for your info..
i tried using seektoend function. but it is still overwriting the value..
can u please help me to solve this problem?
and i don understand how to write each value in each cell? can u explain me little more?
thanks,
rakesh.
|
|
|
|
|
CFile is not the right object to work with excel. Presently what you are doing is, creating a text file with name "example.xls" and writing/overwriting its data.
Maybe using "modeAppend" may help you to get away with the overwriting issue. But still may not serve your purpose.
To modify an "real" excel file, or creating a new excel you need to use Excel . Microsoft provides a way to start excel.exe invisible through your program and then open an existing/create_new excel file and make changes to it. This is called Excel Automation/Office Automation.
http://support.microsoft.com/kb/196776[^]
Suhredayan
|
|
|
|
|
In addition to the Excel Automation suggestions, you could also try using CRecordset with Excel's ODBC interface.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
I you'd prefer the text format over the CRecordset/Automation approaches, you could use a tab character ("\t") or a comma to separate the cells, and a newline to separate the rows. If you only use the CFile::modeCreate flag when opening the file, the file gets truncated to zero length, effectively overwriting your data. Have a look at CFile::modeNoTruncate . Something like this:
CFile theFile;
theFile.Open(_T("example.txt"), CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite, NULL);
CString strOut = _T("Row1Col1\tRow1Col2\tRow1Col3\r\nRow2Col1\tRow2Col2\tRow2Col3");
theFile.Write(strOut, strOut.GetLength() * sizeof(TCHAR));
Note how the file name extension is "txt", you can still open it in Microsoft Excel by right-clicking it. Or you could keep the "xls" extension and keep pretending it's a real binary Excel file. No user will ever notice
|
|
|
|
|
1. FILE * pFile;
pFile = fopen ("C:file.csv","a");
if (pFile!=NULL)
{
CString x2 = "CString1"+","+"CString2"+"\n";
fwrite(x2, x2.GetLength(), 1, pFile);
fclose (pFile);
}
2. Use ,(comma) operator for seperate the objects. use .csv file. it will open in excel.
G.Paulraj
|
|
|
|
|
if it can, show me how to use, please !!!
|
|
|
|
|
No, OpenGL cannot load any images on its own, you will need to use an external library for that (for instance DevIL or FreeImage or maybe GLUT). But I don't know if these libraries support bmf because I never heard of that format.
|
|
|
|
|
sorry , it is my mistake -> bmp.
i need to load a bmp picture by openGL ,then i can use mouse in openGL to draw a point in that pic.
|
|
|
|
|
Then you can use DevIL or FreeImage (I think even GLUT is able to load bmp files but I'm not sure at all, I never used it). Did you look at these libraries ?
If you are interested, you can also look at my second tutorial about OpenGL: it discusses resource management but it is probably it bit more higher level than what you are looking for.
|
|
|
|
|
Hello folks!
Could someone please shed some light on this? I found out the hard way that the file-association technics used in Windows XP and prior to it no longer work in Windows Vista and above. Trying to modify the registry entries to create a file association for a program simply fails in an "access denied" error. So i googled around and found IApplicationAssociationRegistration[^], tried to use it but SetAppAsDefault[^] gave me "file not found". I might be wrong but i figured this means that the application needs to be registered as a "Default Program" before any associations can be done. How to do this? I found this[^] on Microsoft's site, here it tells me that to register an application as default one has to create some registry entries for the application. BUT if i try to create these entries i once again get an "Access Denied". At this point i am a bit lost. I know the documentation there says that usually the installer registers the application as a default program and that installers are usually ran as administrator, however, my program is a very small and simple viewer application which does not have nor need an installer so i want to do the whole association thing from the application itself. Anyone knows how?
Thanks in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thank you. The application i am doing is dialog based, it does not use any document and view architecture really (so no RegisterShellFileTypes), however, i feel strengthened in my belief that this whole file association thing under windows is very badly designed. I think i have now 3 possible ways i can go:
-forget about the whole file-association crample
-have the users run the program as administrator if they ever want any file associations (and i guess changing the whole idea so the program checks for file associations only if it is runned as admin because otherwise it can't change anything on it anyways...)
-try to "elevate" my program under Vista to be able to change registry entries, there doesn't really seem to be any elegant way to do this (you can't change the priviledges of the process once it is already running)
Here[^] it says to use RegOverridePredefKey to "remap" writes to HKEY_CLASSES_ROOT to HKEY_CURRENT_USER, however i do not see how this would help anything since according to the docs it is not HKEY_CURRENT_USER where any registry modifications must go in order to get one's program to be a "default program".
One would think Ms would make something this "basic" as creating file associations more...simple and "standardized".
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
how to resolve 0xC0000005: Access Violation.please let me know
kir_MFC
|
|
|
|
|
kir_MFC wrote: how to resolve 0xC0000005: Access Violation.please let me know
Don't access memory that you're not allowed to.
i.e. Silly question, silly answer...
BTW possibly if you post the offending code then we could help you.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The same way as you fix the previous error message you posted: by using your debugger. Start debugging your program (press F5) and see where the code crashes. Once there you can inspect the different variables to see if everything is as expected. You can also put breakpoints (F9) to break your program at a certain location.
You've been posting on CP for quite a long time already, it is time you learn to use your debugger properly. There's no way you can write quality software without using it. It should become your best friend when fixing problems in your application. Once you know how to use it, you'll see that it will make you gain a HUGE amount of time. So, the time spent in learning how to use it properly is a very good investment, believe me.
|
|
|
|
|
I implemented grep command in win32 console application using vc++ 6.0.i encountered with following problem.grep.exe has encountered a problem and needs to close. We are sorry for the inconvenience.please let me know the solution
kir_MFC
|
|
|
|
|
Use your debugger to locate the exact problem. There's no way to find the source of the problem with so little information.
|
|
|
|
|
Use your debugger to step into your code. Narrow down the problem, post it here with any relevant source code and the call-stack. Only then somebody will be able to help you.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Have you tried this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Is there any device so that I can attach the device to the computer and Insert my sim to the device . How can I develop the software so that I can send the SMS through the computer via that device.
Trioum
|
|
|
|
|
yes - you need to look at purchasing a GSM/GPRS modem
'g'
|
|
|
|