15,891,905 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 Python 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 Member 8172875 (Top 27 by date)
Member 8172875
19-Nov-12 2:17am
View
int itemCount = listBox1.SelectedItems.Count;
string str="";
for (int i = 0; i < itemCount; i++)
{
str += listBox1.SelectedItems[i].ToString() + "','";
}
Member 8172875
19-Nov-12 2:15am
View
thanks Dominic. i have done with some modification on your code and its working properly .. thanks for the help
Member 8172875
18-Nov-12 23:38pm
View
Error 1: The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments
Error 2: Argument '2': cannot convert from 'System.Collections.Generic.List<string>' to 'string[]'
I got two errors while trying your code.. you are correct. i am working on windows application.
Member 8172875
17-Nov-12 2:14am
View
actually i want a string of multiple selected values from listbox. and use this string into where clause for IN() statement. it will fetch all records which are selected by user in listbox and display records on gridview.
Member 8172875
17-Nov-12 2:09am
View
i am using sample code 2 and get this Error 1 'object' does not contain a definition for 'Selected' and no extension method 'Selected' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) C:\Users\admin\Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\PrintSalarySlip.cs 184 47 WindowsFormsApplication1
Member 8172875
17-Nov-12 0:39am
View
if i write the incorrect name. so i will get a compilation error not run time exception. i used correct name. my sample code is
"
string str = "";
foreach(ListItem lstItem in listBox1.Items)
{
if (lstItem.Selected)
{
//str += listBox1.Items.OfType<string>().ToString();
str+=lstItem.Value.ToString()+",";
}
}
if(str!="")
{
str.Remove(str.LastIndexOf(','));
}
"
Member 8172875
16-Nov-12 3:17am
View
string str = "";
foreach(ListItem lstIetm In MyListBox.Items)// through an exception here "unable to cast object of type 'System.String' to 'System.Web.UI.WebControls.ListItem'"
{
If(lstIetm.Selected)
{
str+=lstItem.Value.ToString()+",";
}
}
if(str!="")
{
str.Remove(str.LastIndexOf(','));
}
//Then write your query with in clause.
Select * from <tableName> where Id in (str)
Member 8172875
16-Nov-12 2:55am
View
I got an error "unable to cast object of type 'System.String' to 'System.Web.UI.WebControls.ListItem'"
Member 8172875
16-Nov-12 2:20am
View
thanks for the solution.. i will use it and revert you back...thank you so much
Member 8172875
16-Nov-12 2:01am
View
actually i have no idea about this scenario. i have to select multiple ids from listbox and fetch the data of selected ids from database. display records in gridview.
Member 8172875
16-Oct-12 4:38am
View
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER
Procedure [dbo].[cursorPtechMed]
(
@pErrFlag
Char(1) Output,
@pErrDesc
VARCHAR(500) Output
)
AS
Begin
Begin
Try
DECLARE
EMPCUR CURSOR FOR
SELECT
Priority_No, Pay_Band, Grade_Pay, Basic_Pay, DA, Transp_Alwnc, Gross_Pay, Nett_Pay
FROM
dbo.UCMS_PTECH_MED_SALARY
where
Sal_Date IN(Select Max(Sal_Date) from dbo.UCMS_PTECH_MED_SALARY group by Priority_No)
DECLARE
@Priority_No int, @Basic_Pay Money, @DA Money, @Pay_Band Money,
@temp money, @temp1 money,
@Grade_Pay Money, @Transp_Alwnc Money, @Gross_Pay money, @Nett_Pay money
OPEN
EMPCUR
FETCH
NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay
WHILE
@@FETCH_STATUS=0
BEGIN
set
@temp =@DA
set
@temp1 = @Transp_Alwnc
set
@DA = @DA+ @DA * 0.07
set
@temp=@DA-@temp
set
@Transp_Alwnc = @Transp_Alwnc + @Transp_Alwnc * 0.07
set
@temp1=@Transp_Alwnc-@temp1
set
@Gross_Pay = @Gross_Pay + @temp + @temp1
set
@Nett_Pay = @Nett_Pay + @temp + @temp1
update dbo.UCMS_PTECH_MED_SALARY
set DA=@DA, Transp_Alwnc= @Transp_Alwnc , Gross_Pay=@Gross_Pay, Nett_Pay=@Nett_Pay
FETCH
NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay
END
CLOSE
EMPCUR
DEALLOCATE
EMPCUR
Set
@pErrFlag = 'S'
Set
@pErrDesc = 'S'
End
Try
Begin
Catch
Set
@pErrDesc = ERROR_MESSAGE() + '' + ERROR_LINE() + '' + ERROR_PROCEDURE()
Set
@pErrFlag = 'E'
If
@@trancount > 0
Rollback
RAISERROR
(@pErrDesc,11,1);
End
Catch
End
i did not get the correct value when i update DA and Transp_Alwnc.. update command update the result twice and save it.it means but insert command work properly. for e.g. if i have DA 1000 in row1 and row2.but i m getting result 1144.900 for both the rows. but in insert command result is row1=1070 and row2=1144.900 that is correct result but update command gives wrong values. it update both the row with last incremented value
Member 8172875
16-Oct-12 4:37am
View
Deleted
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER Procedure [dbo].[cursorPtechMedSal] ( @pErrFlag Char(1) Output, @pErrDesc VARCHAR(500) Output ) AS Begin Begin Try DECLARE EMPCUR CURSOR FOR SELECT Priority_No, Pay_Band, Grade_Pay, Basic_Pay, DA, Transp_Alwnc, Gross_Pay, Nett_Pay FROM dbo.UCMS_PTECH_MED_SALARY where Sal_Date IN(Select Max(Sal_Date) from dbo.UCMS_PTECH_MED_SALARY group by Priority_No) DECLARE @Priority_No int, @Basic_Pay Money, @DA Money, @Pay_Band Money, @temp money, @temp1 money, @Grade_Pay Money, @Transp_Alwnc Money, @Gross_Pay money, @Nett_Pay money OPEN EMPCUR FETCH NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay WHILE @@FETCH_STATUS=0 BEGIN set @temp =@DA set @temp1 = @Transp_Alwnc set @DA = @DA+ @DA * 0.07 set @temp=@DA-@temp set @Transp_Alwnc = @Transp_Alwnc + @Transp_Alwnc * 0.07 set @temp1=@Transp_Alwnc-@temp1 set @Gross_Pay = @Gross_Pay + @temp + @temp1 set @Nett_Pay = @Nett_Pay + @temp + @temp1 insert dbo.Backup_UCMS_PTECH_MED_SALARY (Priority_NO, DA, TA) Values(@Priority_No, @DA, @Transp_Alwnc) update dbo.UCMS_PTECH_MED_SALARY set DA=@DA, Transp_Alwnc= @Transp_Alwnc , Gross_Pay=@Gross_Pay, Nett_Pay=@Nett_Pay FETCH NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay END CLOSE EMPCUR DEALLOCATE EMPCUR Set @pErrFlag = 'S' Set @pErrDesc = 'S' End Try Begin Catch Set @pErrDesc = ERROR_MESSAGE() + '' + ERROR_LINE() + '' + ERROR_PROCEDURE() Set @pErrFlag = 'E' If @@trancount > 0 Rollback RAISERROR (@pErrDesc,11,1); End Catch End i did not get the correct value when i update DA and Transp_Alwnc.. update command update the result twice and save it.it means but insert command work properly. for e.g. if i have DA 1000 in row1 and row2.but i m getting result 1144.900 for both the rows. but in insert command result is row1=1070 and row2=1144.900 that is correct result but update command gives wrong values. it update both the row with last incremented value
Member 8172875
16-Oct-12 4:15am
View
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER
Procedure [dbo].[cursorPtechMedSal]
(
@pErrFlag
Char(1) Output,
@pErrDesc
VARCHAR(500) Output
)
AS
Begin
Begin
Try
DECLARE
EMPCUR CURSOR FOR
SELECT
Priority_No, Pay_Band, Grade_Pay, Basic_Pay, DA, Transp_Alwnc, Gross_Pay, Nett_Pay
FROM
dbo.UCMS_PTECH_MED_SALARY
where
Sal_Date IN(Select Max(Sal_Date) from dbo.UCMS_PTECH_MED_SALARY group by Priority_No)
DECLARE
@Priority_No int, @Basic_Pay Money, @DA Money, @Pay_Band Money,
@temp money, @temp1 money,
@Grade_Pay Money, @Transp_Alwnc Money, @Gross_Pay money, @Nett_Pay money
OPEN
EMPCUR
FETCH
NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay
WHILE
@@FETCH_STATUS=0
BEGIN
set
@temp =@DA
set
@temp1 = @Transp_Alwnc
set
@DA = @DA+ @DA * 0.07
set
@temp=@DA-@temp
set
@Transp_Alwnc = @Transp_Alwnc + @Transp_Alwnc * 0.07
set
@temp1=@Transp_Alwnc-@temp1
set
@Gross_Pay = @Gross_Pay + @temp + @temp1
set
@Nett_Pay = @Nett_Pay + @temp + @temp1
insert dbo.Backup_UCMS_PTECH_MED_SALARY (Priority_NO, DA, TA)
Values(@Priority_No, @DA, @Transp_Alwnc)
update dbo.UCMS_PTECH_MED_SALARY
set DA=@DA, Transp_Alwnc= @Transp_Alwnc , Gross_Pay=@Gross_Pay, Nett_Pay=@Nett_Pay
FETCH
NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay
END
CLOSE
EMPCUR
DEALLOCATE
EMPCUR
Set
@pErrFlag = 'S'
Set
@pErrDesc = 'S'
End
Try
Begin
Catch
Set
@pErrDesc = ERROR_MESSAGE() + '' + ERROR_LINE() + '' + ERROR_PROCEDURE()
Set
@pErrFlag = 'E'
If
@@trancount > 0
Rollback
RAISERROR
(@pErrDesc,11,1);
End
Catch
End
i did not get the correct value when i update DA and Transp_Alwnc.. update command update the result twice and save it.it means but insert command work properly.
for e.g. if i have DA 1000 in row1 and row2.but i m getting result 1144.900 for both the rows. but in insert command result is row1=1070 and row2=1144.900 that is correct result but update command gives wrong values. it update both the row with last incremented value
Member 8172875
16-Oct-12 4:07am
View
Deleted
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
alter
Procedure [dbo].[cursorPtechMedSalar]
(
@pErrFlag
Char(1) Output,
@pErrDesc
VARCHAR(500) Output
)
AS
Begin
Begin
Try
DECLARE
EMPCUR CURSOR FOR
SELECT
Priority_No, Pay_Band, Grade_Pay, Basic_Pay, DA, Transp_Alwnc, Gross_Pay, Nett_Pay
FROM
dbo.UCMS_PTECH_MED_SALARY
where
Sal_Date IN(Select Max(Sal_Date) from dbo.UCMS_PTECH_MED_SALARY group by Priority_No)
DECLARE
@Priority_No int, @Basic_Pay Money, @DA Money, @Pay_Band Money,
@temp money, @temp1 money,
@Grade_Pay Money, @Transp_Alwnc Money, @Gross_Pay money, @Nett_Pay money
OPEN
EMPCUR
FETCH
NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay
WHILE
@@FETCH_STATUS=0
BEGIN
set
@temp =@DA
set
@temp1 = @Transp_Alwnc
set
@DA = @Basic_Pay * 0.72
set
@temp=@DA-@temp
set
@Transp_Alwnc = @Basic_Pay * 0.72
set
@temp1=@Transp_Alwnc-@temp1
set
@Gross_Pay = @Gross_Pay + @temp + @temp1
set
@Nett_Pay = @Nett_Pay + @temp + @temp1
insert dbo.Backup_UCMS_PTECH_MED_SALARY (Priority_NO, DA, TA)
Values(@Priority_No, @DA, @Transp_Alwnc)
update dbo.UCMS_PTECH_MED_SALARY
set DA=@DA, Transp_Alwnc= @Transp_Alwnc , Gross_Pay=@Gross_Pay, Nett_Pay=@Nett_Pay
FETCH
NEXT FROM EMPCUR INTO @Priority_No, @Pay_Band, @Grade_Pay, @Basic_Pay, @DA, @Transp_Alwnc, @Gross_Pay, @Nett_Pay
END
CLOSE
EMPCUR
DEALLOCATE
EMPCUR
Set
@pErrFlag = 'S'
Set
@pErrDesc = 'S'
End
Try
Begin
Catch
Set
@pErrDesc = ERROR_MESSAGE() + '' + ERROR_LINE() + '' + ERROR_PROCEDURE()
Set
@pErrFlag = 'E'
If
@@trancount > 0
Rollback
RAISERROR
(@pErrDesc,11,1);
End
Catch
End
now i changed my cursor.. now i am updating rather than inserting a row. it works fine. but now the problem is i have two row .
DA for row 1 is 1000
DA for second row is 100
after running cursor i get result
DA 72 in both the rows as Basic_Pay=1000 for row 1 and 100 for row2
but insert command shows correct result row1=720 and row2=72.
but update command shows 72 for both the rows
Member 8172875
16-Oct-12 2:47am
View
but when i remove priority_no as primary key for checking purpose. it will insert rows. but with some problem:
1. i have 2 rows after insertion total no of rows will be 4...but there are more than 3000 rows get inserted in my table
2. the value of DA and Transp will be 0.000. not updated by its calculated value
Member 8172875
16-Oct-12 2:25am
View
hi amit, thanks for the solution.. yes i want to do the same thing... but i want all the previous record..if m using update command then it will update that row and lost previous data... for checking purpose i modify my table structure and set sal_date primary key instead of priority_no+sal_date. it works but i am getting two problem 1. i have 2 rows after insertion total no of rows will be 4...but there are more than 3000 rows get inserted in my table 2. the value of DA and Transp will be 0.000
Member 8172875
16-Oct-12 2:24am
View
hi amit, thanks for the solution..
yes i want to do the same thing... but i want all the previous record..if m using update command then it will update that row and lost previous data...
for checking purpose i modify my table structure and set sal_date primary key instead of priority_no+sal_date.
it works but i am getting two problem
1. i have 2 rows after insertion total no of rows will be 4...but there are more than 3000 rows get inserted in my table
2. the value of DA and Transp will be 0.000
Member 8172875
16-Oct-12 2:20am
View
but in sal_date is current date. my previous date is 21/08/2012 and current date is 16/10/2012. both the date are different with same priority number. so i dont think so there is a problem in primary composite key
Member 8172875
16-Oct-12 2:12am
View
hi milind .. thanks for the solution .. but i cant update bcz if i update that row then i cant get previous data.. i need all the updated as well as previous data.
and other thing is i have composite primary key (priority_no and sal_date(getdate())) still i am not able to insert
Member 8172875
16-Oct-12 2:07am
View
structure of database priority_no primary key int DA money Basic_pay money Transp_Alwnc money Pay_Band money Grade_Pay money Sal_Date primary key datetime with getdate( i want to insert a duplicate row for all rows present in table with 7% incremented value of DA and Transp_alwnc
Member 8172875
16-Oct-12 2:02am
View
structure of database
priority_no primary key int
DA money
Basic_pay money
Transp_Alwnc money
Pay_Band money
Grade_Pay money
Sal_Date primary key datetime with getdate(
i want to insert a duplicate row for all rows present in table with 7% incremented value of DA and Transp_alwnc
Member 8172875
6-Aug-12 6:25am
View
i didnt find RowNumber.. i think its RowIndex rather than RowNumber
Member 8172875
6-Aug-12 3:46am
View
but i want code. how to add a new row of edited cell in database. on refresh i want both the data with different color on modified cell
Member 8172875
21-Oct-11 4:27am
View
thanks for the help.. this code is working fine. now i am getting the contents line by line but one problem is arising because of table.
When i am trying to read table a special character append at the end of the text. for ex..
1
Hemant rana
mca
2
Pritesh sinha
mca
this is a table with 3cols and 2rows
How can i skip these kind of characters?
Member 8172875
27-Sep-11 2:41am
View
Deleted
The code for Code to open a doc word file
char szFilter[] =
"Word Files (*.*)|*.doc|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog DataRead(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
NULL, NULL,
OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
szFilter,
NULL);
int nFileRead = DataRead.DoModal();
if(IDOK == nFileRead)
{
//Get file name for opening Excel file
CString szFileName = DataRead.GetPathName();
if(szFileName.IsEmpty())
return;
//Do not make Word visible
CEzWordAutomation MsWord(FALSE);
MsWord.OpenWordFile(szFileName);
int i;
int nLineCount = MsWord.GetLineCount();
CString szLine;
CString szMessage;
for(i=1; i<=nLineCount; i++)
{
szLine = MsWord.GetLine(i);
szMessage = szMessage + szLine ;
}
MsWord.CloseDocument(FALSE);
MsWord.ReleaseWord();
MessageBox(szMessage);
}
Code read doc file line by line
CString CWordAutomation::GetLine(int nLine)
{
CString szLine = _T("");
if(NULL == m_pdispWordApp)
return szLine;
VARIANTARG varg1, varg2;
int wdGoToLine = 3; //MsWord constant
int wdGoToAbsolute = 1; //MsWord constant
int wdLine = 5; //MsWord constant
int wdExtend = 1; //MsWord constant
//Got to line
ClearAllArgs();
if (!WordInvoke(m_pdispWordApp, L"Selection", &varg1, DISPATCH_PROPERTYGET, 0))
return szLine;
ClearAllArgs();
AddArgumentInt2(L"What", 0, wdGoToLine);
AddArgumentInt2(L"Which", 0, wdGoToAbsolute);
AddArgumentInt2(L"Count", 0, nLine);
if (!WordInvoke(varg1.pdispVal, L"GoTo", NULL, DISPATCH_METHOD, 0))
return szLine;
//Selection.HomeKey Unit:=wdLine
ClearAllArgs();
AddArgumentInt2(L"Unit", 0, wdLine);
if (!WordInvoke(varg1.pdispVal, L"HomeKey", NULL, DISPATCH_METHOD, 0))
return szLine;
//Selection.EndKey Unit:=wdLine, Extend:=wdExtend
ClearAllArgs();
AddArgumentInt2(L"Unit", 0, wdLine);
AddArgumentInt2(L"Extend", 0, wdExtend);
if (!WordInvoke(varg1.pdispVal, L"EndKey", &varg2, DISPATCH_METHOD, 0))
return szLine;
ClearAllArgs();
if (!WordInvoke(varg1.pdispVal, L"Text", &varg2, DISPATCH_PROPERTYGET, 0))
return szLine;
//Get text from varg2
VARTYPE Type = varg2.vt;
switch (Type)
{
case VT_UI1:
{
unsigned char nChr = varg2.bVal;
szLine = nChr;
}
break;
case VT_I4:
{
long nVal = varg2.lVal;
szLine.Format("%i", nVal);
}
break;
case VT_R4:
{
float fVal = varg2.fltVal;
szLine.Format("%f", fVal);
}
break;
case VT_R8:
{
double dVal = varg2.dblVal;
szLine.Format("%f", dVal);
}
break;
case VT_BSTR:
{
BSTR b = varg2.bstrVal;
szLine = b;
}
break;
case VT_BYREF|VT_UI1:
{
//Not tested
unsigned char* pChr = varg2.pbVal;
szLine = *pChr;
}
break;
case VT_BYREF|VT_BSTR:
{
//Not tested
BSTR* pb = varg2.pbstrVal;
szLine = *pb;
}
case 0:
{
//Empty
szLine = _T("");
}
}
return szLine;
}
Other function related to GetLine()
BOOL CWordAutomation::AddArgumentInt2(LPOLESTR lpszArgName, WORD wFlags, int i)
{
AddArgumentCommon(lpszArgName, wFlags, VT_I2);
m_aVargs[m_iArgCount++].iVal = i;
return TRUE;
}
void CWordAutomation::ClearAllArgs()
{
int i;
for (i = 0; i < m_iArgCount; i++)
{
if (m_awFlags[i] & DISPARG_NOFREEVARIANT)
// free the variant's contents based on type
ClearVariant(&m_aVargs[i]);
else
ReleaseVariant(&m_aVargs[i]);
}
m_iArgCount = 0;
m_iNamedArgCount = 0;
}
void CWordAutomation::ClearVariant(VARIANTARG *pvarg)
{
pvarg->vt = VT_EMPTY;
pvarg->wReserved1 = 0;
pvarg->wReserved2 = 0;
pvarg->wReserved3 = 0;
pvarg->lVal = 0;
}
code for reading word document line by line.... can i modified this function to read data word by word rather than line by line...
The problem with my code is i cant read two dimensional table correctly.. i can read first column of the table...
Member 8172875
27-Sep-11 2:41am
View
Deleted
The code for Code to open a doc word file
char szFilter[] =
"Word Files (*.*)|*.doc|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog DataRead(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
NULL, NULL,
OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
szFilter,
NULL);
int nFileRead = DataRead.DoModal();
if(IDOK == nFileRead)
{
//Get file name for opening Excel file
CString szFileName = DataRead.GetPathName();
if(szFileName.IsEmpty())
return;
//Do not make Word visible
CEzWordAutomation MsWord(FALSE);
MsWord.OpenWordFile(szFileName);
int i;
int nLineCount = MsWord.GetLineCount();
CString szLine;
CString szMessage;
for(i=1; i<=nLineCount; i++)
{
szLine = MsWord.GetLine(i);
szMessage = szMessage + szLine ;
}
MsWord.CloseDocument(FALSE);
MsWord.ReleaseWord();
MessageBox(szMessage);
}
Code read doc file line by line
CString CWordAutomation::GetLine(int nLine)
{
CString szLine = _T("");
if(NULL == m_pdispWordApp)
return szLine;
VARIANTARG varg1, varg2;
int wdGoToLine = 3; //MsWord constant
int wdGoToAbsolute = 1; //MsWord constant
int wdLine = 5; //MsWord constant
int wdExtend = 1; //MsWord constant
//Got to line
ClearAllArgs();
if (!WordInvoke(m_pdispWordApp, L"Selection", &varg1, DISPATCH_PROPERTYGET, 0))
return szLine;
ClearAllArgs();
AddArgumentInt2(L"What", 0, wdGoToLine);
AddArgumentInt2(L"Which", 0, wdGoToAbsolute);
AddArgumentInt2(L"Count", 0, nLine);
if (!WordInvoke(varg1.pdispVal, L"GoTo", NULL, DISPATCH_METHOD, 0))
return szLine;
//Selection.HomeKey Unit:=wdLine
ClearAllArgs();
AddArgumentInt2(L"Unit", 0, wdLine);
if (!WordInvoke(varg1.pdispVal, L"HomeKey", NULL, DISPATCH_METHOD, 0))
return szLine;
//Selection.EndKey Unit:=wdLine, Extend:=wdExtend
ClearAllArgs();
AddArgumentInt2(L"Unit", 0, wdLine);
AddArgumentInt2(L"Extend", 0, wdExtend);
if (!WordInvoke(varg1.pdispVal, L"EndKey", &varg2, DISPATCH_METHOD, 0))
return szLine;
ClearAllArgs();
if (!WordInvoke(varg1.pdispVal, L"Text", &varg2, DISPATCH_PROPERTYGET, 0))
return szLine;
//Get text from varg2
VARTYPE Type = varg2.vt;
switch (Type)
{
case VT_UI1:
{
unsigned char nChr = varg2.bVal;
szLine = nChr;
}
break;
case VT_I4:
{
long nVal = varg2.lVal;
szLine.Format("%i", nVal);
}
break;
case VT_R4:
{
float fVal = varg2.fltVal;
szLine.Format("%f", fVal);
}
break;
case VT_R8:
{
double dVal = varg2.dblVal;
szLine.Format("%f", dVal);
}
break;
case VT_BSTR:
{
BSTR b = varg2.bstrVal;
szLine = b;
}
break;
case VT_BYREF|VT_UI1:
{
//Not tested
unsigned char* pChr = varg2.pbVal;
szLine = *pChr;
}
break;
case VT_BYREF|VT_BSTR:
{
//Not tested
BSTR* pb = varg2.pbstrVal;
szLine = *pb;
}
case 0:
{
//Empty
szLine = _T("");
}
}
return szLine;
}
Other function related to GetLine()
BOOL CWordAutomation::AddArgumentInt2(LPOLESTR lpszArgName, WORD wFlags, int i)
{
AddArgumentCommon(lpszArgName, wFlags, VT_I2);
m_aVargs[m_iArgCount++].iVal = i;
return TRUE;
}
void CWordAutomation::ClearAllArgs()
{
int i;
for (i = 0; i < m_iArgCount; i++)
{
if (m_awFlags[i] & DISPARG_NOFREEVARIANT)
// free the variant's contents based on type
ClearVariant(&m_aVargs[i]);
else
ReleaseVariant(&m_aVargs[i]);
}
m_iArgCount = 0;
m_iNamedArgCount = 0;
}
void CWordAutomation::ClearVariant(VARIANTARG *pvarg)
{
pvarg->vt = VT_EMPTY;
pvarg->wReserved1 = 0;
pvarg->wReserved2 = 0;
pvarg->wReserved3 = 0;
pvarg->lVal = 0;
}
code for reading word document line by line.... can i modified this function to read data word by word rather than line by line...
The problem with my code is i cant read two dimensional table correctly.. i can read first column of the table...
Member 8172875
27-Sep-11 2:41am
View
Deleted
The code for Code to open a doc word file
char szFilter[] =
"Word Files (*.*)|*.doc|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
CFileDialog DataRead(TRUE, // TRUE for FileOpen, FALSE for FileSaveAs
NULL, NULL,
OFN_PATHMUSTEXIST|OFN_OVERWRITEPROMPT,
szFilter,
NULL);
int nFileRead = DataRead.DoModal();
if(IDOK == nFileRead)
{
//Get file name for opening Excel file
CString szFileName = DataRead.GetPathName();
if(szFileName.IsEmpty())
return;
//Do not make Word visible
CEzWordAutomation MsWord(FALSE);
MsWord.OpenWordFile(szFileName);
int i;
int nLineCount = MsWord.GetLineCount();
CString szLine;
CString szMessage;
for(i=1; i<=nLineCount; i++)
{
szLine = MsWord.GetLine(i);
szMessage = szMessage + szLine ;
}
MsWord.CloseDocument(FALSE);
MsWord.ReleaseWord();
MessageBox(szMessage);
}
Code read doc file line by line
CString CWordAutomation::GetLine(int nLine)
{
CString szLine = _T("");
if(NULL == m_pdispWordApp)
return szLine;
VARIANTARG varg1, varg2;
int wdGoToLine = 3; //MsWord constant
int wdGoToAbsolute = 1; //MsWord constant
int wdLine = 5; //MsWord constant
int wdExtend = 1; //MsWord constant
//Got to line
ClearAllArgs();
if (!WordInvoke(m_pdispWordApp, L"Selection", &varg1, DISPATCH_PROPERTYGET, 0))
return szLine;
ClearAllArgs();
AddArgumentInt2(L"What", 0, wdGoToLine);
AddArgumentInt2(L"Which", 0, wdGoToAbsolute);
AddArgumentInt2(L"Count", 0, nLine);
if (!WordInvoke(varg1.pdispVal, L"GoTo", NULL, DISPATCH_METHOD, 0))
return szLine;
//Selection.HomeKey Unit:=wdLine
ClearAllArgs();
AddArgumentInt2(L"Unit", 0, wdLine);
if (!WordInvoke(varg1.pdispVal, L"HomeKey", NULL, DISPATCH_METHOD, 0))
return szLine;
//Selection.EndKey Unit:=wdLine, Extend:=wdExtend
ClearAllArgs();
AddArgumentInt2(L"Unit", 0, wdLine);
AddArgumentInt2(L"Extend", 0, wdExtend);
if (!WordInvoke(varg1.pdispVal, L"EndKey", &varg2, DISPATCH_METHOD, 0))
return szLine;
ClearAllArgs();
if (!WordInvoke(varg1.pdispVal, L"Text", &varg2, DISPATCH_PROPERTYGET, 0))
return szLine;
//Get text from varg2
VARTYPE Type = varg2.vt;
switch (Type)
{
case VT_UI1:
{
unsigned char nChr = varg2.bVal;
szLine = nChr;
}
break;
case VT_I4:
{
long nVal = varg2.lVal;
szLine.Format("%i", nVal);
}
break;
case VT_R4:
{
float fVal = varg2.fltVal;
szLine.Format("%f", fVal);
}
break;
case VT_R8:
{
double dVal = varg2.dblVal;
szLine.Format("%f", dVal);
}
break;
case VT_BSTR:
{
BSTR b = varg2.bstrVal;
szLine = b;
}
break;
case VT_BYREF|VT_UI1:
{
//Not tested
unsigned char* pChr = varg2.pbVal;
szLine = *pChr;
}
break;
case VT_BYREF|VT_BSTR:
{
//Not tested
BSTR* pb = varg2.pbstrVal;
szLine = *pb;
}
case 0:
{
//Empty
szLine = _T("");
}
}
return szLine;
}
Other function related to GetLine()
BOOL CWordAutomation::AddArgumentInt2(LPOLESTR lpszArgName, WORD wFlags, int i)
{
AddArgumentCommon(lpszArgName, wFlags, VT_I2);
m_aVargs[m_iArgCount++].iVal = i;
return TRUE;
}
void CWordAutomation::ClearAllArgs()
{
int i;
for (i = 0; i < m_iArgCount; i++)
{
if (m_awFlags[i] & DISPARG_NOFREEVARIANT)
// free the variant's contents based on type
ClearVariant(&m_aVargs[i]);
else
ReleaseVariant(&m_aVargs[i]);
}
m_iArgCount = 0;
m_iNamedArgCount = 0;
}
void CWordAutomation::ClearVariant(VARIANTARG *pvarg)
{
pvarg->vt = VT_EMPTY;
pvarg->wReserved1 = 0;
pvarg->wReserved2 = 0;
pvarg->wReserved3 = 0;
pvarg->lVal = 0;
}
code for reading word document line by line.... can i modified this function to read data word by word rather than line by line...
The problem with my code is i cant read two dimensional table correctly.. i can read first column of the table...
Show More