16,014,662 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by deepakkumargautam (Top 4 by date)
deepakkumargautam
19-Aug-10 6:34am
View
void g_fnWriteExcelFile(CSite *_objSite,char *_strPath)
{
char Range[7],bufCtr[10];
CString _strOutputName;
CoInitialize(NULL);
Excel::_WorkbookPtr workbook ;
Excel::_ApplicationPtr excel;
Excel::_WorksheetPtr worksheet ;
try
{
Excel::_ApplicationPtr excel ;
// Initialize Excel and make sure it's initialized
HRESULT hr = excel.CreateInstance(L"Excel.Application");
if(FAILED(hr))
{
return ;
}
workbook = excel->Workbooks->Add(static_cast<long>(Excel::xlWorksheet)); // Create the workbook
worksheet = excel->ActiveSheet; // Get the active sheet
//tempstrPath = (char*)malloc(sizeof(_strPath));
_strOutputName = _objSite->m_strPrefix + "_" + "MappingResult";
worksheet->Name=(_bstr_t)_strOutputName;
strcat(_strPath,"\");
_strOutputName = _strOutputName + ".xlsx"; // excel 2007
strcat(_strPath,_strOutputName) ;
_variant_t var;
CDevice *_objDevice = _objSite->m_objDevice;
CDevicePoint *_objDevicePoint = NULL;
///////////////////////////////Header Start/////////////////////////////////////////
int nCounter = 1;
while(_objDevice!=NULL)
{
_objDevicePoint = _objDevice->m_objDevicePoint;
while(_objDevicePoint!=NULL)
{
if(nCounter == 2)
{
CString tempColor = "15" ;
strcpy(Range,"A");
itoa(nCounter,bufCtr,10);
strcat(Range,bufCtr);
worksheet->Range[Range]->Value2 = "Tag Name";
_objDevicePoint = _objDevicePoint->next ;
}
nCounter++;
}
_objDevice = _objDevice->next ;
}
worksheet->SaveAs(_strPath); // saving workshee
workbook->Close(); // Close the workbook
excel->Quit(); // Quit excel
}
catch(_com_error &ce)
{
// Handle the error
AfxMessageBox(ce.ErrorMessage()) ;
}
CoUninitialize();
}
deepakkumargautam
19-Aug-10 6:00am
View
Done that Shiva but stil getting some errorrs "steam underclared undentifier, same for FILE " ?
deepakkumargautam
19-Aug-10 5:34am
View
Hi Shiva,
Thanks for replying, I have embed the code but getting some errors. I guess I need to #include something ? specially for stream and FILE?
: I have accepted the answer, I am new @ codeproject so don't know much.
Thanks
deepakkumargautam
19-Aug-10 5:20am
View
workbook = excel->Workbooks->Add(static_cast<long>(Excel::xlWorksheet)); // Create the workbook
worksheet = excel->ActiveSheet; // Get the active sheet
//some code//
worksheet->SaveAs(_strPath); // here comes the error when I try to save an
// excel file alraedy open