Sring to Object Array problem
Hi every body,
I have string in following format
String s= "root, new Object[]{Folder1,SubA,SubB},Folder2,new Object[]{Folder3,SubC,SubD}, new Object[]{Folder4, new Object[]{SubE,SubSubA}}";And I want to convert in following form
Object[] hierarchy=
"root",
new Object[]{"Folder1","SubA","SubB"},
"Folder2",
new Object[]{"Folder3","SubC","SubD"},
new Object[]{"Folder4",
new Object[]{"SubE","SubSubA"}}
}; Please tell me the way
Thanks in advance
Why would you want to do something like that? Storing unrelated types in a single array/collection is almost always a bad idea.
It looks like you're reconstructing a representation of a file system, so you would do better to write classes (or use existing ones)
that encapsulate that functionality.
Similar Messages
-
Object Array problem in Websphere WebServices
Hi,
Can someone help me out with a situation that I am stuck with in WebServices.
I have a WebService which returns a DTO which has a getter and setter for an array of another type of DTO object.
Sample:-
public class MyDTO extends AnotherDTO implements Serializable {
private InnerDTO qcDtoList[] = new InnerDTO[0];
public MyDTO() {
public InnerDTO[] getQcDtoList() {
return qcDtoList;
public void setQcDtoList(InnerDTO[] resEDXDTOs) {
qcDtoList = resEDXDTOs;
But when I generate the WSDL for the webservice using WSAD 5.1 that uses the above DTO, the server side generated skeleton file looks like:-
public class MyDTO extends AnotherDTO implements java.io.Serializable {
private InnerDTO[] qcDtoList;
public MyDTO() {
public InnerDTO[] getQcDtoList() {
return qcDtoList;
public void setQcDtoList(InnerDTO[] qcDtoList) {
this.qcDtoList = qcDtoList;
As you can see from above, my initialization info is not available in the generated skeleton. I also tried putting the initialization in the constructor, with no effect.
What could be the reason for this? And is it possible to initialize my InnerDTO without losing it in the generated skeleton?
I simply want to initialize the object array.
If I need to modify my WSDL, what additional annotations should I add on the WSDL to get the desired effect?
I use WSAD's (Websphere Studio App Developer) IBM Websphere Webservices protocol and the JDK version is 1.3.1 and WSAD version is 5.1.
I would really appreciate if you can throw light on this?
Thanx and Regds,
Prashanth.Thank you for the quick response. I looked at the example you suggested and made the following changes. Now I'm receiving an "Invalid datatype" error on the "SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer))" statement. I must be missing something simple and I just can't put my finger on it.
PROCEDURE SEL_SEARCH_RESULTS (v_term IN VARCHAR2,
v_categories IN ARCHIVE.integer_aat,
rs OUT RSType)
AS
/* PURPOSE: Return Search Results for the Category and Keyword Provided
VARIABLES:
v_categories = Document Categories array entered
v_term = Keyword entered
rs = Result Set
TYPE tbl_integer IS TABLE OF INTEGER;
tbl_cat tbl_integer;
BEGIN
FOR i IN 1 .. v_categories.COUNT
LOOP
tbl_cat.EXTEND(1);
tbl_cat(i) := v_categories(i);
END LOOP;
OPEN rs FOR
SELECT A.ID,
B.CATEGORY,
A.FILENAME,
A.DISPLAY_NAME,
A.COMMENTS
FROM TBL_ARCHIVE_DOCUMENTS A,
TBL_ARCHIVE_DOC_CAT B,
TBL_ARCHIVE_DOC_KEYWORDS C
WHERE A.ID = B.ID
AND A.ID = C.ID
AND B.CATEGORY IN (SELECT column_value FROM TABLE(CAST(tbl_cat AS tbl_integer)))
AND C.KEYWORD = v_term
ORDER BY A.ID;
END SEL_SEARCH_RESULTS; -
Hey Guys,
I am trying to append or add another set of data to my object array but with no success. What I need is later on in my code I want to add new data to the rows array.
Any advise would be gratefully appreciated. Here is my code:
Object[][] rows =
{ { "AOLX", new Integer(10), new Double(12.1), OrderLocation.BUY, OrderStatus.RECIEVED }, {
"ORCLX", new Integer(55), new Double(34.56), OrderLocation.BUY, OrderStatus.RECIEVED }, {
"CSCOX", new Integer(100), new Double(5.6), OrderLocation.SELL, OrderStatus.PROCESSING }, {
"NXTLX", new Integer(200), new Double(7.8), OrderLocation.BUY, OrderStatus.PROCESSING }, {
"DELLX", new Integer(30), new Double(9.11), OrderLocation.SELL, OrderStatus.CANCELLED }
};Edited by: onlynew4now on Aug 6, 2009 5:29 AMYou got a severe case of Object denial.
I'd start with writing a class like this:
public class Order {
private String name;
private int amount;
private BigDecimal cost;
private OrderLocation location;
private OrderStatus status;
public Order(String name, int amount, BigDecimal cost, OrderLocation location, OrderStatus status) {
this.name = name;
this.amount = amount;
this.cost = cost;
this.location = location;
this.status = status;
public Order(String name, int amount, String cost, OrderLocation location, OrderStatus status) {
this(name, amount, new BigDecimal(cost), location, status);
// add getters and if necessary setters
}Then your code can look like this:
Order[] rows = {
new Order("AOLX", 10, "12.1", OrderLocation.BUY, OrderStatus.RECIEVED),
new Order("ORCLX", 55, "34.56", OrderLocation.BUY, OrderStatus.RECIEVED),
new Order("CSCOX", 100, "5.6", OrderLocation.SELL, OrderStatus.PROCESSING),
new Order("NXTLX", 200, "7.8", OrderLocation.BUY, OrderStatus.PROCESSING),
new Order("DELLX", 30, "9.11", OrderLocation.SELL, OrderStatus.CANCELLED);
}; -
how do i make an object array to have a size ,that of the result set,after the query is executed?
And consider the remarks made by sjasja and others in this zombie newly arisen
from its slumber http://forum.java.sun.com/thread.jspa?threadID=680177 -
Problem when using object array as parameter of server-side event
Hi Friends,
I had defined an event in component interface of Component A, with object array as its parameter. but when I define event-handler for this event in Component B, the type of parameter in generated event-handler method is just the class itself instead of an array.
It's a bug or array parameter is not support by server-side event in WD4J?
Thanks in advanced.I think you are trying to do the editing of parameter from the java editor.
Do it via the controller editer. Go the methods tab. Select the actionhandler.
In the parameter section edit the paramter. Change the dimensions here.
Regards,
Ashwani Kr Sharma -
Java Null Pointer Exception when assigning a value to an Object Array
I am working on a webservice where the request can contain a dynamic array of SingleOwnerRequestNodeDetail objects. I need to read these objects in and sort them according to an orderNbr that is contained in the object.
I am attempting to read these object into a Comparable class and sort them. I am having problems when I try to insert the objects into my object array ComparableBO[]. I get the following error: Exception during processing: java.lang.NullPointerException
Any assistance would be greatly appreciated.
Here's my class:
public class ComparatorBO implements Comparable {
private SingleOwnerRequestNodeDetail nodeDetailInfo;
private int orderNbr;
public SingleOwnerRequestNodeDetail getNodeDetailInfo() {
return nodeDetailInfo;
public void setNodeDetailInfo(SingleOwnerRequestNodeDetail nodeDetailInfo) {
this.nodeDetailInfo = nodeDetailInfo;
public int getOrderNbr() {
return Integer.parseInt(nodeDetailInfo.getSingleOwnerRequestOrderNbr());
public void setOrderNbr (int orderNbr) {
this.orderNbr = orderNbr;
public int compareTo(Object anotherNodeDetailInfo)throws ClassCastException {
if (!(anotherNodeDetailInfo instanceof ComparatorBO))
throw new ClassCastException ("An single owner request node detail object is expected");
int anotherNodeDetailOrderNbr = ((ComparatorBO)anotherNodeDetailInfo).getOrderNbr();
return this.orderNbr - anotherNodeDetailOrderNbr;
}Here's the code where I read in the objects and attempt to place them in the comparableBO[]
ComparatorBO[] comparatorBOArray = null;
comparatorBOArray = new ComparatorBO[requestInfo.length];
for (int i=0; i < requestInfo.length; i++)
SingleOwnerRequestNodeDetail nodes = new SingleOwnerRequestNodeDetail();
ComparatorBO comparatorBO = new ComparatorBO();
nodes.setSingleOwnerRequestNodeID(requestInfo.getSingleOwnerRequestNodeID());
nodes.setSingleOwnerRequestNodeType(requestInfo[i].getSingleOwnerRequestNodeType());
nodes.setSingleOwnerRequestOpCode(requestInfo[i].getSingleOwnerRequestOpCode());
nodes.setSingleOwnerRequestOrderNbr(requestInfo[i].getSingleOwnerRequestOrderNbr());
comparatorBO.setNodeDetailInfo(nodes);
*comparatorBOArray[i].setNodeDetailInfo(comparatorBO.getNodeDetailInfo());*
comparatorBOArray[i].setOrderNbr(Integer.parseInt(nodes.getSingleOwnerRequestOrderNbr()));imadeveloper wrote:
I am working on a webservice where the request can contain a dynamic array of SingleOwnerRequestNodeDetail objects. I need to read these objects in and sort them according to an orderNbr that is contained in the object.
I am attempting to read these object into a Comparable class and sort them. I am having problems when I try to insert the objects into my object array ComparableBO[]. I get the following error: Exception during processing: java.lang.NullPointerException
Any assistance would be greatly appreciated.
Here's my class:
public class ComparatorBO implements Comparable {
private SingleOwnerRequestNodeDetail nodeDetailInfo;
private int orderNbr;
public SingleOwnerRequestNodeDetail getNodeDetailInfo() {
return nodeDetailInfo;
public void setNodeDetailInfo(SingleOwnerRequestNodeDetail nodeDetailInfo) {
this.nodeDetailInfo = nodeDetailInfo;
public int getOrderNbr() {
return Integer.parseInt(nodeDetailInfo.getSingleOwnerRequestOrderNbr());
public void setOrderNbr (int orderNbr) {
this.orderNbr = orderNbr;
public int compareTo(Object anotherNodeDetailInfo)throws ClassCastException {
if (!(anotherNodeDetailInfo instanceof ComparatorBO))
throw new ClassCastException ("An single owner request node detail object is expected");
int anotherNodeDetailOrderNbr = ((ComparatorBO)anotherNodeDetailInfo).getOrderNbr();
return this.orderNbr - anotherNodeDetailOrderNbr;
}Here's the code where I read in the objects and attempt to place them in the comparableBO[]
ComparatorBO[] comparatorBOArray = null;
comparatorBOArray = new ComparatorBO[requestInfo.length];
for (int i=0; i < requestInfo.length; i++)
SingleOwnerRequestNodeDetail nodes = new SingleOwnerRequestNodeDetail();
ComparatorBO comparatorBO = new ComparatorBO();
nodes.setSingleOwnerRequestNodeID(requestInfo.getSingleOwnerRequestNodeID());
nodes.setSingleOwnerRequestNodeType(requestInfo[i].getSingleOwnerRequestNodeType());
nodes.setSingleOwnerRequestOpCode(requestInfo[i].getSingleOwnerRequestOpCode());
nodes.setSingleOwnerRequestOrderNbr(requestInfo[i].getSingleOwnerRequestOrderNbr());
comparatorBO.setNodeDetailInfo(nodes);
*comparatorBOArray[i].setNodeDetailInfo(comparatorBO.getNodeDetailInfo());*
comparatorBOArray[i].setOrderNbr(Integer.parseInt(nodes.getSingleOwnerRequestOrderNbr()));
Well normally when someone wont tell me what line the error occured in I copy paste their code into my compiler and find out. But you have other classes which you have not shown us so I cannot help you.
Incase you missed my point, please tell us where the error occured! -
Trouble writing to object array
Hi I did a semester of java 2 years ago and I'm trying to remember what I knew so please bear with me...
I am extracting data from an xml file and then writing that information to an object array called files containing 4 string and 1 array. This files array is in turn an element in another object array containing 400 files arrays called records.
It appeared to be working but when I want it to print out which ever record I have selected it only prints out the last record! It seems to be overwriting each files array with the next?
Another problem I can only print out an element of the array not the entire thing?
Please help have spent weeks on this
Here is the code:
Object[] Records = new Object[400];
Object files[] = new Object[5];
NodeList records = doc.getElementsByTagName("record");
for( int i = 0; i < records.getLength();i++)
Element record = (Element) records.item(i);
NodeList headers = record.getElementsByTagName("header");
Element header = (Element) headers.item(0);
NodeList ids = header.getElementsByTagName("identifier");
for(int j = 0; j < ids.getLength(); j++){
Element id = (Element) ids.item(j);
String ID = getText(id);
files[0] = ID;
NodeList metadatas = record.getElementsByTagName("metadata");
Element metadata = (Element) metadatas.item(0);
NodeList citeseers = metadata.getElementsByTagName("oai_citeseer:oai_citeseer");
Element citeseer = (Element) citeseers.item(0);
NodeList titles = citeseer.getElementsByTagName("dc:title");
for(int k = 0; k < titles.getLength(); k++){
Element title = (Element) titles.item(k);
String TITLE = getText(title);
files[1] = TITLE;
NodeList subjects = citeseer.getElementsByTagName("dc:subject");
for(int m = 0; m < subjects.getLength(); m++){
Element subject = (Element) subjects.item(m);
String SUBJECT = getText(subject);
files[2] = SUBJECT;
NodeList descriptions = citeseer.getElementsByTagName("dc:description");
for(int n = 0; n < descriptions.getLength(); n++){
Element description = (Element) descriptions.item(n);
String DESCRIPTION = getText(description);
files[3] = DESCRIPTION;
String[] Names = new String[20];
NodeList authors = citeseer.getElementsByTagName("oai_citeseer:author");
for(int l = 0; l < authors.getLength(); l++){
Element author = (Element) authors.item(l);
Names[l] = author.getAttribute("name");
files[4] = Names;
System.out.println("The id is "+files[0]);
System.out.println("The title is "+ files[1]);
System.out.println("The Subject is "+ files[2]);
System.out.println("The Description is "+ files[3]);
for(int q=0; q < authors.getLength(); q++){
System.out.println("The Names are "+ ((String[])files[4])[q]);
//Records[i] = files;
System.out.println(((Object[])Records[0])[0]);I'm afraid I'm not going to make you a millionaire but I feel so relieved at the moment that if I had a million I'd give it to you!!Yeah, I know you won't make me a millionaire, but I can dream... :)
thanks for all your helpYou are welcome. Do you understand why you needed to move the creation of the "files" array. -
Array problem (empty).
Hi everybody,
I'm using Crystal X and I have the following query
IdField Field1 Field2
1 CCC 8
1 GGG 3
1 DDD 2
2 AAA 7
I want the following output
IdField
1 CCC GGG DDD Field2 define different format to Field1 (different background color)
2 AAA
My report is grouped by IdField. As the output for Field1 has a different format depending on Field2. I want to write the Field1+Field2 values for each IdField in an Array, I have the following formulas, but the array looks empty, I have changed the array declaration as global and still is empty
Section: ReportHeader
Formula InitArray
shared stringvar Array DataArray;
redim DataArray[30];
Section: Details (Suppresed)
Formula AddDataToArray
shared numbervar iCounter;
shared stringvar Array DataArray;
iCounter := iCounter + 1;
DataArray[iCounter] := {Command.Field1} + "-" + {Command.Field2};
Section: Footer Group1a
Formulla FillTextFromArray
shared numbervar sDataVal;
shared stringvar Array DataArray;
sDataVal := DataArray[1]; //DataArray[1] shoud be = "CCC-8"
left(sDataVal, len(sDataVal)-2);
{@DisplayData1}= DataArray[1]; //This is my problem the array is empty
Section: Footer Group1b
Display the following data
IdField @DisplayData1 @DisplayData2 @DisplayData3 ...
I added 50 formulas to display each Field1 value with different formats. I know these columns are fixed, but I coudn't find any other way.
I have 3 question:
??? What is wrong on my array than in formula "FillTextFromArray" is empty???
??? Is there another way to refence a formula or a text object different than FormulaName or TextObjectName???, like an object array or something, because I will be dealing with 50 formulas to write the value and to change the format
??? How to make reference to a text object, in case I would change the 50 formulas by 50 text objects
Please help with any of the 3 questions or any ideas to make the report
thanks
ccYou can try another way like
create anew formula @Initialize
whileprintingrecords;
stringvar str:="";
Now place this in group header of IDField
Now Create another formula @Evaluate
whileprintingrecords;
stringvar str;
str:=str" ";
Place this in detail section
Create another formula like @Display
whileprintingrecords;
stringvar str;
place this in group footer of IDFIeld and right click on this formula and go to format field and check the option "can grow".
Now you can suppress the sections group header and details section to show the values in a single line in each group footer.
Hope this helps!
Raghavendra -
what do i have to do to create and object array in a class of other class. i tried to created an object of that class first and the create the array by the compiler complains that there is a problem. here is the code.
classJTBar---------------------------------------------------
ackage JTShapes;
import java.awt.*;
public class JTBar extends JTFilledRectangle{
int height=20; int length=0;//i will use the inheritated methods
public JTBar(){//contructor that will be called on creating object
setHeight(20);//method of class JTRectangle
setWidth(0);//method of class JTRectangle
public void setLengh (int x){
length = x;
public void incLengh(int y){
length = length+y;
}//end class
User class
port JTShapes.*;
import JTUtils.*;
import javax.swing.*;
public class User extends JTUser{
public void begin(){
JTBar jtbarobject= new JTBar();
JTBar[] arrayObj= new JTBar[8];
String[] weekDay= {"Monday", "Tuesday", "Wednesday", "Thuersday",
"Friday", "Saturday", "Sunday"};You don't have to do this:
String[] weekDay = new String[]{"Monday", "Tuesday", "Wednesday", "Thuersday", "Friday", "Saturday", "Sunday"};
This works fine:
String[] weekDay= {"Monday", "Tuesday", "Wednesday", "Thuersday", "Friday", "Saturday", "Sunday"};
What kind of Exception are you getting? I'm guessing you're getting a NullPointerException?
Looks like you're declaring your array correctly, but you are not initializing it:
JTBar[] arrayObj= new JTBar[8];
for (int i = 0; i < arrayObj.length; i++) {
arrayObj[i] = new JTBar();
} -
Is there any way to directly convert and object Array to a Collection object. Basically i need to create a ArrayList from Object Array. The ArrayList has a constructor and also provides a method addAll() that accept Collection as parameter. So the problem becomes , how to convert Object Array to collection. As per my understanding all arrays should be essentially Collection Interface subclass.
So why am i not able to cast?
What is wrong in calling Object Array a sub class of Collection?
// OrderLineItem[] is the object array that i wish to have as ArrayList
// This code generates error -
//"ErpOrder.java": Error #: 364 : cannot cast gal.ERP.OrderLineItem[] to java.util.Collection
public void setLineItems( OrderLineItem[] arrOrderLineItem ) {
m_arrLineItems = new ArrayList((Collection)arrOrderLineItem);
}Is there no way except iterating through the array and adding individual Objects to ArrayList?By "Object array" do you mean an Array class, or do you mean an Object[]? They are different. The Array class wraps an Object[] and provides useful methods to manipulate it.
There is no such thing as a Collection object, per say. "Collection" is an interface implemented by many objects such as LinkedList, Vector, ArrayList, HashSet, and TreeSet.
The Collection interface is designed to be an interface to any object that can keep a mutable list of other Objects, check to see if an Object is in that list, and iterate through all Objects in the list.
As far as resources go, I suggest the API reference at http://java.sun.com/j2se/1.4.1/docs/api/index.html. -
Object Array Data Provider Refresh Possible bug
Hello
I am having a problem with Object Array Data Provider in terms that the table's data is not changed corectly after a request as expected, but after two requests.
Steps to reproduce the bug:
0. Create a new Visual Web project, call it 'test'.
Set 'Bundled Tomcat ' or 'Sun 9' as deploy target server.
Edit 'Page1' of the project.
1. Create an Entity class, simple class that has only getters and setters with a few fields (lets say 'id' and 'name').
2. In the SessionBean1 that is generated by the framework create an array of Entity class named 'entityArr', and getters and setters for this field.
3. Add a new Array Object Data Provider on the page and set in its properties as array the array created in the previous step 'entityArr (SessionBean1)'.
4. Add a new table component, and set as data provider the provider created in step 3.
In the Table's Layout map the fields from the Entity class, and set whatever compnents you desire for each component's type or leave the default ones (Static Text).
5. Add a 'property change trigger component' on the page. I called it like this because I tried the following :
5.1 A text field and a button to submit the text value
5.2 A Calendar component with autosubmit
5.3 A DropDown with autosubmit.
6. On the property change trigger component created at step 5 set a value_changed method that changes the the array that should be displayed by the table.
For Example, for a DropDown component, you will have a method like this :
public void dropDown1_processValueChange(ValueChangeEvent event) {
String idStr = (String) event.getNewValue();
System.out.println("Entity id :"+idStr);
if(idStr .equals("item1")) {
fillSessionBean1(true);
else {
fillSessionBean1(false);
getSessionBean1().setItemName(idStr);
private void fillSessionBean1(boolean fillValues) {
Entity[] values ;
if(fillValues) {
values = new Entity[4];
for ( int i=0;i<values.length; i++) {
Entity entity = new Entity();
entity.setDescription("Description "+i);
entity.setName("Name "+i);
entity.setId(i) ;
values[i] = entity;
else {
//values = new Entity[0];
values = null;
getSessionBean1().setEntityArr(values);
7. When running the program, if the selected is Item1, the table does not show the array set if on this branch.
I am using :
Netbeans 5.5 build 20061017100,
Visual Web Pack 070104_2,
Ent.Pack 20061212
jdk 1.6.0
Operating Systems : Both Linux Suse10 and Windows.
If anyone has a solution for this please let me know.OK
While no one responded, I had to think for myself.
There is a bug in the code generated by netbeans or there is nowhere specified that if you attach an array to a data provider you will have to notify by hand the data provider that the array has changed.
You will have to put this line that is generated in init function in your valuechanged functions :
objectArrayDataProvider1.setArray((java.lang.Object[])getValue("#{SessionBean1.entityArr}"));
I think this aproach is a little bit wrong, even it works.
I believe the data provider should be notified the array has been changed.
There could be a much more simple aproaches :
1. In the code generated by netbeans, if you attach an array to a data provider the data provider will be notified after any set(Object[])
2. The data provider could have a function so you will ne anle to attach to the data provider an Object (the session bean, in my case) and the name of the function that retrieves the array (in my case, 'getEntityArr') .
The code generated by netbeans could add this function easily.
Maybe there are any other better aproaches, and I might be wrong.
It's good that it works. -
How To Load SINGLE CELL Value as Object - In 2D Object Array - InvalidCastException
Setup: ---- VB.net - Visual Studio 2010 - Excel Version 2010 - Option Strict ON
The following WORKS FINE all day long for loading MULTIPLE range values IE: ("F2:F5") or more into a 2D Object Array... No problem... as in the following..
Dim myRangeTwo As Range = ws.Range("F2:F5") ' MULTIPLE CELL RANGE
Dim arr2(,) As Object = CType(myRangeTwo.Value(XlRangeValueDataType.xlRangeValueDefault), Object(,))
The ws.range("F2:F5") values are stuffed into the myRangeTwo range variable as 2D Objects and then those are easily stuffed into the 2D object array...
But this does not work for a SINGLE cell range...
Dim myRangeTwo As Range = ws.Range("F2:F2") ' SINGLE CELL RANGE F2 ONLY
Dim arr2(,) As Object = CType(myRangeTwo.Value(XlRangeValueDataType.xlRangeValueDefault), Object(,))
This triggers an Invalid Cast Exception error on trying to load into the arr2(,).. because the ws.range("F2:F2") is stuffed into the myRangeTwo variable as a "string"
not as an object therefore is not possible to stuff it into an Object Array and so correctly causes the Invalid Cast Error...
How do you handle this seemingly ridiculously simple problem ??
thanks... CjHello,
Simply answer, you need to determine if the range is a single cell or multiple cells. So the following is geared for returning a DataTable for a start and end cell addresses that are different, granted there is no check to see if the cells are valid i.e.
end cell is before start cell i.e.
Since B1 and B10 is a valid range we are good but if we pass in F1:F1 or F10:F10 we must make a decision as per the if statement at the start of the function and if I were expecting this to happen I would have another function that returned a single value.
Option Strict On
Option Infer On
Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office
Imports System.Runtime.InteropServices
Module ExcelDemoIteratingData_2
Public Sub DemoGettingDates()
Dim dt As DataTable = OpenExcelAndIterate(
IO.Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"GetDatesFromB.xlsx"),
"Sheet1",
"B1",
"B10")
Dim SomeDate As Date = #12/1/2013#
Dim Results =
From T In dt
Where Not IsDBNull(T.Item("SomeDate")) AndAlso T.Field(Of Date)("SomeDate") = SomeDate
Select T
).ToList
If Results.Count > 0 Then
For Each row As DataRow In Results
Console.WriteLine("Row [{0}] Value [{1}]",
row.Field(Of Integer)("Identifier"),
row.Field(Of Date)("SomeDate").ToShortDateString)
Next
End If
End Sub
Public Function OpenExcelAndIterate(
ByVal FileName As String,
ByVal SheetName As String,
ByVal StartCell As String,
ByVal EndCell As String) As DataTable
If StartCell = EndCell Then
' Decide logically what to do or
' throw an exception
End If
Dim dt As New DataTable
If IO.File.Exists(FileName) Then
Dim Proceed As Boolean = False
Dim xlApp As Excel.Application = Nothing
Dim xlWorkBooks As Excel.Workbooks = Nothing
Dim xlWorkBook As Excel.Workbook = Nothing
Dim xlWorkSheet As Excel.Worksheet = Nothing
Dim xlWorkSheets As Excel.Sheets = Nothing
Dim xlCells As Excel.Range = Nothing
xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlWorkBooks = xlApp.Workbooks
xlWorkBook = xlWorkBooks.Open(FileName)
xlApp.Visible = False
xlWorkSheets = xlWorkBook.Sheets
' For/Next finds our sheet
For x As Integer = 1 To xlWorkSheets.Count
xlWorkSheet = CType(xlWorkSheets(x), Excel.Worksheet)
If xlWorkSheet.Name = SheetName Then
Proceed = True
Exit For
End If
Runtime.InteropServices.Marshal.FinalReleaseComObject(xlWorkSheet)
xlWorkSheet = Nothing
Next
If Proceed Then
dt.Columns.AddRange(
New DataColumn() _
New DataColumn With {.ColumnName = "Identifier", .DataType = GetType(Int32), .AutoIncrement = True, .AutoIncrementSeed = 1},
New DataColumn With {.ColumnName = "SomeDate", .DataType = GetType(Date)}
Dim xlUsedRange = xlWorkSheet.Range(StartCell, EndCell)
Try
Dim ExcelArray(,) As Object = CType(xlUsedRange.Value(Excel.XlRangeValueDataType.xlRangeValueDefault), Object(,))
If ExcelArray IsNot Nothing Then
' Get bounds of the array.
Dim bound0 As Integer = ExcelArray.GetUpperBound(0)
Dim bound1 As Integer = ExcelArray.GetUpperBound(1)
For j As Integer = 1 To bound0
If (ExcelArray(j, 1) IsNot Nothing) Then
dt.Rows.Add(New Object() {Nothing, ExcelArray(j, 1)})
Else
dt.Rows.Add(New Object() {Nothing, Nothing})
End If
Next
End If
Finally
ReleaseComObject(xlUsedRange)
End Try
Else
MessageBox.Show(SheetName & " not found.")
End If
xlWorkBook.Close()
xlApp.UserControl = True
xlApp.Quit()
ReleaseComObject(xlCells)
ReleaseComObject(xlWorkSheets)
ReleaseComObject(xlWorkSheet)
ReleaseComObject(xlWorkBook)
ReleaseComObject(xlWorkBooks)
ReleaseComObject(xlApp)
Else
MessageBox.Show("'" & FileName & "' not located. Try one of the write examples first.")
End If
Return dt
End Function
Private Sub ReleaseComObject(ByVal sender As Object)
Try
If sender IsNot Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(sender)
sender = Nothing
End If
Catch ex As Exception
sender = Nothing
End Try
End Sub
End Module
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. -
When can we expect a patch for Object Array List Data Provider?
Hey JSC Team!
When can we expect maybe, just maybe a minor patch for the Object Array List Data Provider loading class problem? Next Month? This Year? Next Year? Near Future? Long in the future? Sometime in the 22nd century?I think one of the problem is
when u declare the ObjectListDataProvider in ur backing bean
it doesnt appear in the design time straight away
u have to clean build close and re open the project
which is quite time consuming. -
I am trying to do a simple task that I thought would be very easy and quick to do but I have run into problems
I am trying to get the user to input a number and based on that number make a text field to become visible based on it. So if the user input 3 the first 3 textfields would become visible. I have 10 textfields and I don't need any error handling yet as I can do that later but this is my code:
var x=NumericField1.rawValue;
for(var i=0; i<=x; i++)
TextField1[i].presence="visible";
I think my problem is creating the object array as all I did was double clicked in the library to create the textfields and the names come up as TextField1 then in the grey shaded area right beside it is the number 0. The next one is called TextField1 with 1 greyed out beside it.
Can anyone help me out?
ThanksSO IF YOU TRY IN JAVASCRIPT THIS WON'T WORK SO DO THIS IN "FORMCALC"
i=NUMIRICFIELD.RAWVALUE;
TextField1[i].presence="visible";
PLEASE DO THIS IN FORMCALC &FEEDBACK ME
[email protected] -
Hi,
I am having problem initializing object array - here is my scenario -
I have created class a -
public class A {
Public String a1;
Public String a2;
Public String a3;
}the I have created class b
public class B {
Public A [] aa;
}and I want to initialiaze my class bi in anoither clas c
public class C{
A ar = new A;
ar.aa[0].a1 = "test"
}this gives me null ..please anybody help me
Neha
}Thanks for the reply ..I know this is not good code ..but I have to write the classes in this way in SAP to create the Webservice ...the SAP side understand this type of structure only ..I still got the same error ..here are my original classes -
public class GRDataItem {
public String AUFNR ;
public String EXIDP ;
public String EXIDC;
public String MATNR ;
public String WERKS ;
public String CHARG ;
public String VEMNG ;
public String VEMEH ;
public String CWMVEMEH ;
public String CWMVEMNG ;
public String STATUS;
public class GRDataTab {
public GRDataItem [] grItem;
Public class webservice {
int sn = 20 ;
GRDataTab tab = new GRDataTab();
tab.grItem = new GRDataItem[sn];
tab.grItem[1].AUFNR = "12";
}Thanks for all your help
Neha
Maybe you are looking for
-
I am in the process of setting up a new bc site. Testing the system, i created a product with a price of 5.40. Created a member. Had that member buy the product by COD method. The order shows in orders as it should on the backend invoice showing 5.40
-
Select from wwsbr_url$ throws error
I have a custom item type with a procedure in which I would like to select from the wwsbr_url$ table. If I execute my select statement from SQL*Plus (as portal30) everything works fine. When I view the items in OP, however, the procedure is returning
-
ITunes match option not showing in iPad2. Running iOS 5.1
iTunes match option is not showing in my iPad 2 neither in my iPhone 4S under Music settings but works ok in my iMac and MacMini. Is there any setting to enable it in iOS? All devices are connected to the same apple ID
-
When the power button is pressed, the fans spin up for about 1-2 seconds and the optical drive starts to initialize, then they both stop and nothing else happens. The hardrive does not appear to be starting. I have tried to start up in target mode bu
-
Downloadin the trial version of Elements and its asking for a serial number. Where do I get that if Im not purchasing it and only want the trial?