|
No my problem is this.
If i am reading "12:00:12" from excel then through this code
_variant_t vItem = pRange->Item[ 1 ][ iColumn ];
_bstr_t bstrText( vItem );
i am getting 0.500138888888889
now what i do to get "12:00:12" from excel.
|
|
|
|
|
MsmVc wrote: i am getting 0.500138888888889
This is the internal Excel date and time format. I cannot remember the exact details but I think the datetime is in the form D.S, where D is the number of days since the 'epoch'*, and S is number of seconds since midnight divided by 86,400 (the total number of seconds in a day).
So in your case to get the time we multiply 0.500138888888889 by 86,400 which gives 43,212 or 12 hours, 0 minutes and 12 seconds.
*epoch is the base date from which counting starts. I think Excel may start at year zero.
|
|
|
|
|
Thanks for nice and smart concept.But my problem is something different.
See i am getting values from Excel "0.500138888888889" this data can be Time format or double format.So how can i format this data.I think i need to identify data type of excel before format(Change).
Please help me
|
|
|
|
|
i think need to post some more code.
try
{
.
CoInitialize(NULL);
while ( m_list.DeleteColumn( 0 ) );
HRESULT hr;
CFileDialog fileDlg(TRUE, _T("xls"), NULL, OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,_T("Excel Files|*.xls;*.xlsx|"));
if (fileDlg.DoModal () == IDCANCEL)
return;
CString OpenFile = fileDlg.GetPathName ();
Excel::_ApplicationPtr pApplication;
if (FAILED( pApplication.CreateInstance( _T("Excel.Application") ) ) )
{
return;
}
_variant_t varOption( (long) DISP_E_PARAMNOTFOUND, VT_ERROR );
Excel::_WorkbookPtr pBook = pApplication->Workbooks->Open( (_bstr_t)OpenFile, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption, varOption );
if ( pBook == NULL )
{
pBook->Close( VARIANT_FALSE );
pApplication->Quit( );
Errorf( _T("Failed to open Excel file!") );
return;
}
for(int i=1;i<4;i++)
{
Excel::_WorksheetPtr pSheet = pBook->Sheets->Item[ i ];
_bstr_t na=pSheet->GetName();
if ( pSheet == NULL )
{
return;
}
Excel::RangePtr pRange = pSheet->GetRange( _bstr_t( _T("A1") ), _bstr_t( _T("Z1" ) ) );
if ( pRange == NULL )
{
Errorf( _T("Failed to get header cell range( A1:iv )!") );
return;
}
int iColumns = 0;
for ( int iColumn = 1; iColumn < 26; ++iColumn )
{
_variant_t vItem = pRange->Item[ 1 ][ iColumn ];
_bstr_t bstrText( vItem );
if ( bstrText.length( ) == 0 )
break;
m_list.InsertColumn(iColumns++,bstrText,LVCFMT_LEFT,170 );
}
pRange = pSheet->GetRange( _bstr_t( _T("A2") ), _bstr_t( _T("Z16384" ) ) );
int iColumn=0;
for ( int iRow = 1; ; ++iRow )
{
for ( iColumn = 1; iColumn <= iColumns; ++iColumn )
{
_variant_t vItem = pRange->Item[ iRow ][ iColumn ];
_bstr_t bstrText( vItem );
if ( bstrText.length( ) == 0 )
break;
if ( iColumn == 1 )
m_list.InsertItem( iRow - 1, bstrText );
else
m_list.SetItemText( iRow - 1, iColumn - 1, bstrText );
}
if ( iColumn == 1 )
break;
}
for ( int iColumn = 1; iColumn <= iColumns; ++iColumn )
m_list.SetColumnWidth( iColumn, LVSCW_AUTOSIZE_USEHEADER );
}
pBook->Close( VARIANT_FALSE );
pApplication->Quit( );
}
catch(...)
{
}
Here i take some constant value so please don't make issues of constant values.
|
|
|
|
|
MsmVc wrote: I think i need to identify data type of excel before format(Change).
Yes I guess that's right. Unfortunately I cannot help with that as I am not sure how to get the information from Excel as to what type of information is held in a particular cell. I suspect that there is no way; if you write a number in an Excel cell, you can format it any way you like. However, you are the only person that knows what that number represents, all Excel knows is how you want it to be displayed on the screen!
|
|
|
|
|
|
Good morning
I agree with Richard.
You know your excel document. so if you expect to find time cells inside, you should detect that when reading it.
I think you could try to retreive from excel the cell format.
detect the date time mode and react accordingly.
if you cannot find the cell format then if i remeber well you can retreive the value of your cell as a string. in that case i would post analyze it and if something like "07:07:13" is detected i will do the tranformation for a time.
bye the way did you try to analyze the type of your read vItem to see what is in the BSTR value for a date time cell ?
Regards
FRanck.
|
|
|
|
|
Good morning
Thank for reply.
i will do the tranformation a time
I am waiting for you response.
BSTR value for a date time cell ?
i try to do that but didn't find through this code.
_variant_t vItem = pRange->Item[ 1 ][ iColumn ];
COleDateTime dt;
switch (vItem.vt )
{
case VT_DATE:
{
dt = vItem.date;
break;
}
case VT_R8:
{
AfxMessageBox("dOUBLE");
break;
}
case VT_BSTR:
{
_bstr_t bstrText( vItem );
break;
}
case VT_EMPTY:
{
TRACE("\t\t<empty>");
break;
}
}
cursor jump out side the case.
|
|
|
|
|
Hi
If your switch detect nothing i guess it is because the date time is really stored as a double inside excel.
Your call:
pRange->Item [1][iColumn]
always return the value as a double at least for date and time.
To by-pass that i would try to retreive the Text of the cell which is what the cell show.
Text if from VBA doc but it should exist the same entry point in automation.
In that case i am pretty sure you will recieved the 10:23:00 value.
In the web site above there is an explanation about how to translate an excel date time:
http://www.cpearson.com/excel/datetime
The last soulution:
If your date time cell is at a fixed place then just retrieve the value and translate as explain in the above link.
Regards
Franck
|
|
|
|
|
i think it's my fault to not describe proper.
Date and time cell is not fixed.If i know this cell have date time then i easy convert it.
My problem is how to know data time format.
|
|
|
|
|
Hi
I think like you do yourself when you watch an excel spread sheet.
Either you retrieve the Text dispalyed by the cell and you recognize that it is a time.
or you right click on the cell and look at the format of the cell.
and you see something like dd:mm:ss
Right now in your code you just query the double value of the cell it is not enough.
You have to explore your cell deeper in order to be able to make a decision.
To do that you can:
Getting the STRING/TEXT displayed by the cell.
and or the FORMAT associated with the cell.
Regards.
|
|
|
|
|
Respected Sir
i know that all things to check right click on cell get format.
explore your cell deeper in order to be able to make a decision
i am same thing last 3 or 4 post.I don't have idea to got the cell format.Try to understand my problem.Plz help me
|
|
|
|
|
code bellow will return you something like: "12:56:32"
for a cell containing time.
Excel::RangePtr pRange = pSheet->GetRange( _bstr_t(_T("A1") ) );
if ( pRange == NULL ){
return;
}
_bstr_t sText= pRange->GetText();
it exist also something called CellFormat.
but i cannot find how to call it.
Sorry for the short answer but i do not have good code sample with me right now.
regards
|
|
|
|
|
i wanted to type
Excel::RangePtr pRange = pSheet->GetRange( _bstr_t(_T("A1") ) );
if ( pRange == NULL ){
return;
}
_bstr_t sText= pRange->GetText();
|
|
|
|
|
thanks i am trying to do through code.
|
|
|
|
|
I use ms front-page to edit html help file, I like its check-spelling feature .
But when path of a html file is too long (my case: 151 characters), pront-page can not open and edit it.
I have to move it to a short folder then move back for C++ program to display.
I bother me so often.
Can you solve the long-path problem of front-page?
|
|
|
|
|
includeh10 wrote: Can you solve the long-path problem of front-page?
Yes. Stop using FrontPage.
|
|
|
|
|
Hi all,
please explain me where is regedit located in Pocket PC.
and how can create and registry here.
please help me for this.
thanks in advance.
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
|
Hi,
I'm Developing a live video streaming application in vc++ using DirectX VideoMixingRenderer filter. I can able to draw rubber band rectangle on live video using DirectX SetAlphaBitmap() through my mouse move. if my video frame size(4CIF) is greater than my picture box control size, it's working fine. Suppose, my video frame size(CIF) is less than my picture box control size,
1) only 3 sides of the rectangle can be visible.
2) sometimes 2 sides only can be visible.
3) Above two context has been happen randomly.
Please, somebody help me out from this issue.
Thanx in advance,
Regards
Surez
|
|
|
|
|
Hello,
I implemented an expandable/shrinkable dialog (with a "more >>"/"<< Less") button and that works well, except that the dialog items that are not visible can still be accessed and modified (by pressing the Tab key for instance). So I was thinking about simply disabling non-visible items.
For that, I don't want to have to specify manually the item ids that need to be disabled when the dialog is shrunk. So I was thinking about going through all items of my dialog and checking whether they are contained in the visible area, then disable them if not visible.
What function would I need to use for that? Is there something like: GetDlgItem(index)?
Thank you
|
|
|
|
|
use:
GetWindow(..) with child and nex params.
IsWindowVisible(...)
and
EnableWindow(...)
|
|
|
|
|
Thank you for your reply.
I tried it, but somehow I cannot loop through the elements (GetWindow never returns NULL with the GW_HWNDNEXT parameter).
I however managed to get it right by using the EnumChildWindows function.
|
|
|
|
|
I'm baffled. I know where the problem line is. I just don't understand the problem except to add that it likely relates to either pointer or reference or both. Hopefully, all code needed is included. Thanks in advance. Sorry for the code dump, but I think it may all be needed....(since I don't really know what the problem is....
Unhandled exception at 0x5dd97b3f (msvcp90d.dll) in Parser6.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.
FROM OUTPUT...
First-chance exception at 0x5dd97b3f (msvcp90d.dll) in Parser6.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.
Unhandled exception at 0x5dd97b3f (msvcp90d.dll) in Parser6.exe: 0xC0000005: Access violation writing location 0xcdcdcdcd.
Here is the line from some internal file that is getting pointed at by the compiler. FileName = xutility. Bad line is labeled.
inline void __CLR_OR_THIS_CALL _Container_base_secure::_Orphan_all() const
{
_Lockit _Lock(_LOCK_DEBUG);
if (_Myfirstiter != _IGNORE_MYITERLIST)
{
for (_Iterator_base **_Pnext = (_Iterator_base **)&_Myfirstiter;
*_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
BAD LINE HERE --> (*_Pnext)->_Mycont = 0;
*(_Iterator_base **)&_Myfirstiter = 0;
}
}
Here is the Collector constructor with the problem code labeled near the end.
Note that the constructor is taking in a reference. This may be related to error.
#include "Collector.h"
#include "Token_stream.h"
#include "Multiplier.h"
#include <vector>
#include <iostream>
using namespace std;
Collector::Collector(Multiplier& myMultiBox, int MaxSNM): myMultiplier(myMultiBox)
{
cin.clear();
cin.ignore(1000, '\n');
BaseIP = GetOctets2( MaxSNM);
NetworkBits = ConvertToNetworkBits( BaseIP);
vector<SimpleBox*> Boxes;
vector<int> test(31,9);
for (int i = 0; i < (myMultiplier.GetTheBoxSet()).size(); i++)
{
Boxes = (myMultiplier.GetABoxMaker(i))->GetMyBoxes();
for (int z = 0; z < Boxes.size(); z++)
{
THIS DOESN'T WORK-> Boxes[z]->SetMyNetworkBits(test);
THIS DOESN'T WORK-> Boxes[z]->SetMyBaseIP(BaseIP);
THIS WILL RUN ALONE-> Boxes[z]->PRINT_NETWORK();
}
}
}
Here is main
#include "AllHeaders.h"
using namespace std;
int main()
try{
StartMeUp KickStart;
Multiplier MultiBox(KickStart.GetMyHosts());
BoxMaker* temp = MultiBox.GetABoxMaker(0);
BoxMaker* temp1 = MultiBox.GetABoxMaker(1);
BoxMaker* temp2 = MultiBox.GetABoxMaker(2);
BoxMaker* temp3 = MultiBox.GetABoxMaker(3);
PureStack FirstT(temp );
StackSmallHigh SecondT(temp1);
PureReserve ThirdT(temp2);
ReserveSmall FourthT(temp3);
cout << endl;
int MaxSNM = temp->GetMyVLSM();
Collector TheCollector(MultiBox, MaxSNM);
system("PAUSE");
return 0;
}
catch (exception& e)
{
cerr << e.what() << endl;
keep_window_open ("~1");
return 1;
}
catch (...)
{
cerr << "exception \n";
keep_window_open ("~2");
return 2;
}
all headers:
#include <iostream>
#include <vector>
#include "StartMeUp.h"
#include "Multiplier.h"
#include "Stroustrup.h"
#include "MakeSmall.h"
#include "BoxMaker.h"
#include "PureStack.h"
#include "StackSmallHigh.h"
#include "PureReserve.h"
#include "ReserveSmall.h"
#include "Collector.h"
Here are the .h files
Collector
#ifndef Collector_h
#define Collector_h
#include "Multiplier.h"
#include "Token_stream.h"
#include <vector>
using std::vector;
class Collector
{
public:
Collector(Multiplier&, int );
int GetMyBaseIP();
vector<int> GetMyNetworkBits() ;
private:
int MaximumMask;
vector<Token> BaseIP;
vector<int> NetworkBits;
vector<Token> GetNumber(bool, vector<Token>, int, char SNM = '*', int MaxSNM = 30);
vector<Token> GetNumberAndDot(bool broken, vector<Token> Octets, int limit);
vector<Token> GetOctets2( int );
vector<int> ConvertToNetworkBits(vector<Token>);
Multiplier myMultiplier;
};
#endif
Multiplier
#ifndef Multiplier_h
#define Multiplier_h
#include "Token_stream.h"
#include "BoxMaker.h"
#include <vector>
using std::vector;
class Multiplier
{
public:
Multiplier(vector<Token> hosts_in);
vector<BoxMaker*> GetTheBoxSet();
BoxMaker* GetABoxMaker(int i);
int GetMyVLSM( int BM);
private:
vector<Token> hosts;
vector<BoxMaker*> BoxSet;
};
#endif
SimpleBox
#ifndef SimpleBox_h
#define SimpleBox_h
#include "Token_stream.h"
#include <vector>
using std::vector;
class SimpleBox
{
public:
SimpleBox (vector<Token> hosts);
void ResetStatics();
void SetMyNetworkBits(vector<int>);
void SetMyBaseIP(vector<Token> );
void SetNetwork(int network );
void SetVLSM(int SNM);
void PrintBoxValue();
void SetMyHostsTest();
int GetMyBlockSize();
int GetMyNetwork();
int GetMyVLSM();
void PRINT_NETWORK();
private:
vector<Token> myHostsVector;
vector<int> myHostBits;
int myBlockSize;
int myHosts;
int myNetwork;
int myHostElement;
int myVLSM;
void FigureBlockSize();
int myBroadCast;
vector<int> myNetworkBits;
vector<Token> BaseIP;
int MaxSNM;
static int s_network;
static int s_globalcounter;
};
#endif
BoxMaker
#ifndef BoxMaker_h
#define BoxMaker_h
#include "SimpleBox.h"
#include "Token_stream.h"
#include <vector>
class BoxMaker
{
public:
BoxMaker (vector<Token> Hosts_in, int i);
void PRINT_TEST();
vector<SimpleBox*> GetMyBoxes();
void SetMyNetwork(int network, int number );
void SetMyVLSM(int network, int VLSM);
int GetMyVLSM();
private:
vector<Token> theHosts;
vector<SimpleBox*> myBoxes;
};
#endif
SetmyNetworkBits
#include "SimpleBox.h"
#include <vector>
void SimpleBox::SetMyNetworkBits (vector<int> theNetworkBits)
{
myNetworkBits = theNetworkBits;
}
SetmyBaseIP
#include "SimpleBox.h"
#include <vector>
void SimpleBox::SetMyBaseIP (vector<Token> theBaseIP)
{
BaseIP = theBaseIP;
}
|
|
|
|
|
When the crash occurs, take a look at the call stack to see where is the line in error in your code. This will already give you some clues. If you are still stuck, tell us where the code occurs exactly in your code.
|
|
|
|