There has to be a better way than the following code. My main area of
question is getting data from a cell.
This following statement is the only way I can get it to work. Just seems
like to much clutter.
ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
private void ProcessToss( string[] filePaths)
{
int MaxRow;
string Col5, Col6, Col12, LookUp;
string ConvType;
XL._Worksheet CurWorkSheet;
using (XCel xlHand = new XCel()) // using a class that handles excel
connection
{
xlHand.Get_NewApp();
foreach( string TossFilePath in filePaths) // Can process multiple excel
files
{
xlHand.OpenFile (TossFilePath);
xlHand.ActivateWS(1);
MaxRow = xlHand.LastRow - 8 ;
CurWorkSheet = (XL._Worksheet )xlHand.CurrentSheet;
for ( int Row =9; Row <= MaxRow; Row++)
{
xlHand.StatusBar = string.Format("Current row is {0}", Row);
ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
if( ConvType == "T")
{
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
5],CurWorkSheet.Cells[Row, 5]).Value2 == null)
Col5 = "";
else
Col5 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
5],CurWorkSheet.Cells[Row, 5]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
6],CurWorkSheet.Cells[Row, 6]).Value2.ToString() == null)
Col6 = "";
else
Col6 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
6],CurWorkSheet.Cells[Row, 6]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
12],CurWorkSheet.Cells[Row, 12]).Value2.ToString() == null)
Col12 = "";
else
Col12 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row,
12],CurWorkSheet.Cells[Row, 12]).Value2.ToString();
LookUp = ConvType + Col5 + Col6 +Col12;
if( this.textTable.Contains(LookUp))
{
CurWorkSheet.Cells[ Row, 4 ] = this.textTable[LookUp].ToString ();
}
}
}
xlHand.SaveWB (TossFilePath.Substring (0,18) + "UniqueText.xls");
xlHand.StatusBar = "";
}
}
}
Thanks 4 2901
Dwight,
It seems you are calling the accessors directly (get_Range), instead of
just the properties (Range). Why are you doing this?
Also, you are creating a number of references to the excel workbooks and
pages that are not being cleaned up correctly, and therefore, will leave a
number of excel instances running.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dwight Trumbower" <se******@somewhereelse.com> wrote in message
news:Oj**************@TK2MSFTNGP12.phx.gbl... There has to be a better way than the following code. My main area of question is getting data from a cell. This following statement is the only way I can get it to work. Just seems like to much clutter. ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ;
private void ProcessToss( string[] filePaths) { int MaxRow; string Col5, Col6, Col12, LookUp; string ConvType;
XL._Worksheet CurWorkSheet;
using (XCel xlHand = new XCel()) // using a class that handles excel connection { xlHand.Get_NewApp(); foreach( string TossFilePath in filePaths) // Can process multiple excel files { xlHand.OpenFile (TossFilePath); xlHand.ActivateWS(1); MaxRow = xlHand.LastRow - 8 ; CurWorkSheet = (XL._Worksheet )xlHand.CurrentSheet; for ( int Row =9; Row <= MaxRow; Row++) { xlHand.StatusBar = string.Format("Current row is {0}", Row); ConvType = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 3],CurWorkSheet.Cells[Row, 3]).Value2.ToString() ; if( ConvType == "T") {
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 5],CurWorkSheet.Cells[Row, 5]).Value2 == null) Col5 = ""; else Col5 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 5],CurWorkSheet.Cells[Row, 5]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 6],CurWorkSheet.Cells[Row, 6]).Value2.ToString() == null) Col6 = ""; else Col6 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 6],CurWorkSheet.Cells[Row, 6]).Value2.ToString();
if(CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 12],CurWorkSheet.Cells[Row, 12]).Value2.ToString() == null) Col12 = ""; else Col12 = CurWorkSheet.get_Range (CurWorkSheet.Cells[Row, 12],CurWorkSheet.Cells[Row, 12]).Value2.ToString();
LookUp = ConvType + Col5 + Col6 +Col12; if( this.textTable.Contains(LookUp)) { CurWorkSheet.Cells[ Row, 4 ] = this.textTable[LookUp].ToString (); } } } xlHand.SaveWB (TossFilePath.Substring (0,18) + "UniqueText.xls"); xlHand.StatusBar = ""; } } }
Thanks
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:<Ow**************@TK2MSFTNGP15.phx.gbl>... Dwight,
It seems you are calling the accessors directly (get_Range), instead of
just the properties (Range). Why are you doing this?
Because this is the only way I could get the data. Any other method I tried
failed.
Dwight
Dwight,
How did it fail? You couldn't compile? An exception was thrown?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Dwight Trumbower" <se******@somewhereelse.com> wrote in message
news:uq*************@tk2msftngp13.phx.gbl... "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<Ow**************@TK2MSFTNGP15.phx.gbl>...
Dwight,
It seems you are calling the accessors directly (get_Range), instead of
just the properties (Range). Why are you doing this?
Because this is the only way I could get the data. Any other method I tried failed.
Dwight
I tried this ConvType = CurWorkSheet.Cells[Row,3].ToString() ; Which I think
should work, but all it does is return a string, "System.__ComOBject".
I either recieved casting errors or not the correct data.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2***************@TK2MSFTNGP09.phx.gbl... Dwight,
How did it fail? You couldn't compile? An exception was thrown?
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Dwight Trumbower" <se******@somewhereelse.com> wrote in message news:uq*************@tk2msftngp13.phx.gbl... "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<Ow**************@TK2MSFTNGP15.phx.gbl>...
Dwight,
It seems you are calling the accessors directly (get_Range), instead of
just the properties (Range). Why are you doing this?
Because this is the only way I could get the data. Any other method I tried failed.
Dwight
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robin Tucker |
last post by:
Hi there,
I have a database on my test machine that will need to be installed on users
machines. I would like to create the database with the given schema on the
users machine and also with...
|
by: deko |
last post by:
How to run action query against linked table?
I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table.
When I attempt to run an action query against the linked table I get this...
|
by: trialproduct2004 |
last post by:
Hi all
i am having application storing data in excel sheet.
This applicaton is in C# .net.
I want to update rows of excel sheet in C#.
Can some one help me how to do it.
please help me.
Thanks...
|
by: Luis Esteban Valencia |
last post by:
Hello Everyone,
Iam an intermediate ASP.Net programmer and iam facing a challenging task.
I have a table in MS-SQL server database called 'Members'. The table has
following fields...
...
|
by: JaxDawg |
last post by:
Hey folks...
I've got an interesting problem. I'm updating and displaying an excel
spreadsheet (using com) from a php file. Works great in the debugger
(PhpEd 4.6), but not otherwise. I assume...
|
by: somanyusernamesaretakenal |
last post by:
What I am trying to achieve:
Basically I have generated a report in access. This report needs to be updated using excel. (Updating the new data, not changing existing data)
What I did was I...
|
by: bbasberg |
last post by:
Hello,
I have been struggling with this problem for DAYS and have googled my heart out as well as reading any books I could get my hands on but I cannot find any specific references to my problem....
|
by: Neil Chambers |
last post by:
This is more likely a question for an SQL group but as I'm using powershell
and dotnet it may
be relevant
Overview: I'm trying to pull data from Excel into a DataSet - modifying the
DataSet -...
|
by: joolzhaines |
last post by:
Hi,
Does anyone know how to sort an excel speadsheet? I have a C# app that does almost everything else but when I try and sort I get an ojbect reference error!
I have tried running excel and...
|
by: Bill Schanks |
last post by:
I have a winform app (VB 2005) that allows users to export data to
excel, make updates to the excel file and import the data from that
Excel file and update the database.
My question is: Is it...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |