|
You could create a small helper method or class that converts a row and column number into A1 style notation.
Veni, vidi, abiit domum
|
|
|
|
|
You can refer to a specific column, or set of columns, using the Columns collection and set its properties
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Actually i want to get the range of excel and set it colour and font
currently i am doing like this
Microsoft.Office.Interop.Excel.Range last = excelApp.Cells.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell, Type.Missing);
Microsoft.Office.Interop.Excel.Range range = excelApp.get_Range("A1", last);
range.Font.Bold = true;
range.Font.Size = 12;
range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
range.Cells.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.SteelBlue);
but it actually set the colour of all the rows , i just want to do it for first row which is my column header
|
|
|
|
|
Your original post said that you wanted to set the attributes of a column, not the row headers.
To find the last used cell in a row, I have used this code (VBA, but you should be able to work out what it is doing.
Dim WS As Worksheet
Dim LastCell As Range
Dim LastCellRowNumber As Long
Set WS = Worksheets("Sheet1")
With WS
Set LastCell = .Cells(.Rows.Count, "C").End(xlUp)
LastCellRowNumber = LastCell.Row
End With
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
|
Hi i have a datatable having columns Col1 and Col2
Col1 Col2
A,B,C,D P,Q,R
I want to get the final output in datatable as
Col1 Col2
A P
B Q
C R
D
The first datatable will always have one row but the number of columns will vary . The final datatable should be exact replica of first datatable but the column values in first datatable separated by comma should be displayed as a row in final table. Please help.
|
|
|
|
|
Is there a way to identify how many items does the first column have?
I can see that the P, Q, R values are for the second column, how would you know where to start splitting?
superselector wrote:
Col1 Col2
A P
B Q
C R
D
|
|
|
|
|
The number of items may vary in a culumn.. but one thing is consistent that values will be seperated by comma,its just a sample i have given for understanding of the question. also the number of columns in first datatable is dynamic. it will change based on certain condition but irrespective of the number of columns i want to replicate this datatable and display those comma separated values in a row. The final datatable should have as many rows as the highest lenght of the splitted value
|
|
|
|
|
OK, maybe I was not clear, lets have this example:
DataTable 1:
Column1, Column2, Column3
DataTable 2:
Value1, Value2, Value3, Value4, Value5, Value6, Value7, Value8
The final result for you should be like below?
Column1, Column2, Column3
Value1, Value2, Value3
Value4, Value5, Value6
Value7, Value8
if the above representation is OK, its quite simple, you just have to:
1. Add to the new DataTable the content of the first DataTable
2. Add a new row to the new DataTable, start to add the values
3. When you reached the length of the first DataTable (or first row of the current DataTable) you need to start a new row.
|
|
|
|
|
Thanks , I was able to get it working.
|
|
|
|
|
Ok, if I am understanding correctly, I would approach it like this.
Loop through each column
Convert the data from that column to a 'table' - I do this with some SSRS reports. There are a lot of links about doing this example 1, example 2.
I would try putting each into it's own table then combining them in the end, but it seems like there should be an easier way.
|
|
|
|
|
I am Making Application in visual studio 2010 in windows form using C#
I want to get scan images from scanner.
How can i do???
Please help
Thank You
Sanket
|
|
|
|
|
A quick search found this[^] article here on CodeProject.
|
|
|
|
|
Hi! I trying to use DataContractSerializer to save objects with crossreference. It´s two lists of objects.
I doesn´t get a error but even though the file is created it does´t work to get it back.
Maybe it´s better to use BinaryFormatter?
Some of my code:
DataContractSerializer xs = new DataContractSerializer(typeof(List<Customer>));
DataContractSerializer xs2 = new DataContractSerializer(typeof(List<Book>));
Book-class:
[KnownType(typeof(FaktaBok))]
[KnownType(typeof(BarnBok))]
[KnownType(typeof(SportBok))]
[DataContractAttribute()]
public class Book
{
[DataMember]
protected int isbn = 0;
[DataMember]
protected string titel = null;
[DataMember]
protected string author;
[DataMember]
protected int price;
[DataMember]
protected String isType = null;
[DataMember]
protected Kund biblioteksKund = null;
One derived class:
[DataContractAttribute()]
public class SportBok : Bok
{
[DataMember]
private string sport;
Serialize:
using (Stream s = File.Create(path))
{
xs.WriteObject(s, CustomerList);
}
using (Stream s2 = File.Create(path2))
{
xs2.WriteObject(s2, BookList);
}
DeSerialize:
if (File.Exists(path))
{
using (Stream s = File.OpenRead(path))
{
CustomerList = (List<Kund>)xs.ReadObject(s);
}
}
if (File.Exists(path2))
{
using (Stream s2 = File.OpenRead(path2))
{
BookList = (List<Bok>)xs2.ReadObject(s2);
}
}
|
|
|
|
|
I have done some modification for your code -
[KnownType(typeof (FaktaBok))]
[KnownType(typeof (BarnBok))]
[KnownType(typeof (SportBok))]
[DataContractAttribute()]
public class Book
{
[DataMember]
public int IsBn = 0;
[DataMember]
public string Titel = null;
[DataMember]
public string Author;
[DataMember]
public int Price;
[DataMember]
public String IsType = null;
}
public void SerializerTestMethod()
{
List<Book> books = new List<Book>
{
new Book()
{
Author = "author1",
IsBn = 1,
IsType = "istype1",
Price = 10,
Titel = "booktitle1"
},
new Book()
{
Author = "author2",
IsBn = 2,
IsType = "istype2",
Price = 20,
Titel = "booktitle2"
}
};
string writeTo = @"FilePath";
DataContractSerializer xs2 = new DataContractSerializer(typeof (List<Book>));
using (Stream s2 = File.Create(writeTo))
{
xs2.WriteObject(s2, books);
}
List<Book> outBook = null;
if (File.Exists(writeTo))
{
using (Stream s2 = File.OpenRead(writeTo))
{
outBook = (List<Book>) xs2.ReadObject(s2);
}
}
} }
}
|
|
|
|
|
Well, the reason I didn´t even get an error was because the Form_Load didn´t fire.
But now that I fixed that I get "unable to serilalize" due to elements not being closed or something like that.
The application is a library and customers can lend books.
What I do is save a list of books in a customer objekt so you know what books the customer borrowed.
What exactly is your code doing?
|
|
|
|
|
As per the subject, problem using DataContractSerializer, I have updated your contract with public properties. And the DataContract is getting serialized.
|
|
|
|
|
The only thing I can see you have changed is that you made the SerializerTestMethod.
Did you change anything else?
|
|
|
|
|
When using DataContract it is advisible to use Public properties instead of protected.
That is my other change ... Following is the serialized datacontract with sample data.
<ArrayOfBook xmlns="http://schemas.datacontract.org/2004/07/TestSampApp" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Book>
<Author>author1</Author>
<IsBn>1</IsBn>
<IsType>istype1</IsType>
<Price>10</Price>
<Titel>booktitle1</Titel>
</Book>
<Book>
<Author>author2</Author>
<IsBn>2</IsBn>
<IsType>istype2</IsType>
<Price>20</Price>
<Titel>booktitle2</Titel>
</Book>
</ArrayOfBook>
|
|
|
|
|
|
Hi guys,
I have the above error, it errors on the first line of my code:
HtmlDocument doc = (HtmlDocument)Enquiry_Sourcing_Netcomponents.Document;
doc.GetElementById("Session_Username").SetAttribute("value", "XXXXX");
doc.GetElementById("Session_Password").SetAttribute("value", "XXXXX");
doc.GetElementById("").InvokeMember("click");
HtmlElementCollection theElementCollection = doc.GetElementsByTagName("input");
HtmlElementCollection elems = doc.GetElementsByTagName("input");
foreach (HtmlElement elem in theElementCollection)
{
String nameStr = elem.GetAttribute("name");
if (nameStr != null && nameStr.Length != 0)
{
String contentStr = elem.GetAttribute("content");
System.Windows.MessageBox.Show("Document: " + Enquiry_Sourcing_Netcomponents.ToString() + "\nDescription: " + contentStr);
}
}
Any ideas?
|
|
|
|
|
Member 8811089 wrote: Any ideas? Yes, you cannot cast an object type to a dissimilar one - it does not work. So whatever class Enquiry_Sourcing_Netcomponents.Document is (mshtml.HTMLDocumentClass ), it is not the same as a System.Windows.Forms.HtmlDocument type.
Veni, vidi, abiit domum
|
|
|
|
|
What exactly is "Enquiry_Sourcing_Netcomponents.Document" ?
Why do you think it is convertible to Type HtmlDocument ?
Is HtmlDocument in this case the same thing as mshtml.HTMLDocument ?
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Enquiry_Sourcing_Netcomponents is the name of the browser control in the project
|
|
|
|
|
You are probably using the "Microsoft Web Browser" control added to the toolbox from the "COM" tab when selecting Toolbox items.
Use the "WebBrowser" control from the toolbox located under the "All Windows Forms" node in the toolbox.
|
|
|
|
|
Hi TnTinMn,
I suggest you move your thoughtful reply to the top-level of this thread; I think you might have given the OP the answer to their problem; perhaps, since your reply has been inserted as a reply "underneath" my response, the OP might miss it.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|