|
|
Yeah, I've only just started experimenting with this. It's pretty cool.
Kevin
|
|
|
|
|
I want to merge cells in a table in word 2003 from visual studio 2005 C#.
I manage to merge cells once in a table but when I try to merge other cells in the same table I get an error that says that the rows is not accessable because som cells have been merged.
This is the way I do it.
Word.Range range = MyWordApplication.Selection.Range;
range.Start = wordTable.Rows.Item(1).Cells.Item(2).Range.Start;
range.End = wordTable.Rows.Item(2).Cells.Item(2).Range.End;
range.Cells.Merge();
When I try it once more with other cells I get an error.
Does anyone have any Idea how I can get this to work?
Is there another way to select cells and then merge them?
I think that my way maybe selects all cells from row 1 column 2 to row 2 column 2 but I only want to select these two cells.
If you have any idea please let me know. Thanks!
|
|
|
|
|
Hi Larza.
To answer what I'm assuming you already know, yes, you're not specifying your range properly. When you try to merge a 2nd time, you're re-merging cells that are already merged.
I set my range a little differently. I have 1 line of code that specifies the 2 specific cells I wish to work with(and every cell within their range).
Try using it and see if it helps.
range = Worksheet.get_Range(Worksheet.Cells[1, 1], Worksheet.Cells[1, 2]);
range.Merge(true);
This code never gives me a problem. Try it and see if it helps.
-Goalie35
|
|
|
|
|
Hi! sorry for my late reply.
Thanx for your help but I have a few questions.
What type is the Worksheet?
I have an object of type Word.ApplicationClass.
But I can't find the worksheet.
Won't your range be from the first cell to your last cell?
I mean if you write it like this:
range = Worksheet.get_Range(Worksheet.Cells[1, 1], Worksheet.Cells[2, 2]);
Will the range then only contain 2 cells or every cell between the cells?
Thanx!
|
|
|
|
|
worksheet is an item of excel.
Word.Cell mergeBeginCell = wordTable.Cells(1, 2);
Word.Cell mergeEndCell = wordTable.Cell(2, 2);
mergeBeginCell.Merge(mergeEndCell);
|
|
|
|
|
Hi there,
Is there anyway that I can print the html file from commandline without showing print dialog?
I tried ShellExecuteEx and it does nothing.
Thank you.
|
|
|
|
|
Have you looked at PrintDocument?
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref8/html/T_System_Drawing_Printing_PrintDocument.htm
Example:
class Program
{
static Font printFont = new Font("Arial", 10);
static void Main(string[] args)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += new PrintPageEventHandler(doc_PrintPage);
doc.Print();
}
static void doc_PrintPage(object sender, PrintPageEventArgs e)
{
float leftMargin = e.MarginBounds.Left;
float topMargin = e.MarginBounds.Top;
float yPos = topMargin + (printFont.GetHeight(e.Graphics));
e.Graphics.DrawString("Hello", printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
e.HasMorePages = false;
}
}
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Hello,
I've derived Stream class to receive an internet audio stream.
But the DirectSound class can't play this because of the missing length and position informations.
But I don't have this, because the stream has no end!
How can I solve this?
|
|
|
|
|
Freak.2k wrote: I've derived Stream class to receive an internet audio stream.
But the DirectSound class can't play this because of the missing length and position informations.
But I don't have this, because the stream has no end!
1) Create a SecondaryBuffer object.
2) Set the length to some amount, say 8192, for example.
3) Create two arrays, each with a length half as long as the length of the SecondaryBuffer .
4) Initialize the buffer with Notify objects to notify you when the buffer reaches position 0 and half the length of the buffer.
5) Read data from your stream and place it into the first array.
6) Write the array data to the SecondaryBuffer .
7) Play the SecondaryBuffer with the looping option.
8) As you get notified by the SecondaryBuffer read another array from your stream and write it to the buffer.
This should work ok as long as your stream is staying ahead of your buffer, no guarrantees since this is an internet audio stream, so you may want to make the arrays large enough to give the internet stream a good head start. And be prepared to handle the situation when there are no bytes yet available from your stream.
Hope this helps.
|
|
|
|
|
Hello everyone,
I have an Array which holds list of items. Some of the items in the list are repeated (Undesirable).
Can someone tell me how I can remove/rearange/rebuilt the array without the repeated items?
Thank you very much and have a great weekend.
Khoramdin
|
|
|
|
|
Just off the top of my head... this seems good, it's O(n)
<font>public datatype[] UnduplicateArray(datatype[] startarray)
{
List<datatype> endarray = new List<datatype>();
foreach (datatype d in startarray)
if (!endarray.Contains(d))
endarray.Add(d);
return endarray.ToArray();
}
</datatype></datatype></font>
Last modified: 1hr 31mins after originally posted --
|
|
|
|
|
eggsovereasy wrote: this seems good, it's O(n)
Are you sure?
The List.Contains method loops throught each item in the collection looking for an existing item. That doesn't seem very good...
I would rather use a Dictionary, as that uses a hash table, which is much faster when looking for an existing item.
---
single minded; short sighted; long gone;
|
|
|
|
|
You are absolutely correct, I didn't consider what Contains() was doing, so its probably more like O(n^2).
|
|
|
|
|
I've got a .NET 2 generic library that does operations on any kind of list. I have a Distinct method in that library that returns only the unique elements in the list. It looks something like:
public static IEnumerable<T> Distinct<T>(IEnumerable<T> items)
{
Queue<T> distinct = new Queue<T>();
foreach (T element in items)
{
if (!distinct.Contains(element))
{
distinct.Enqueue(element);
}
}
return distinct;
}
Then you can use it like this:
string[] myStrings = { "hello", "world", "hello" };
IEnumerable<string> distinct = Distinct(myStrings);
|
|
|
|
|
This is more flexible than my example, but its the same logic. I would use this were I the OP.
|
|
|
|
|
Considering that you are taking in and returning IEnumerable<t>, wouldn't it be better to use yield return, instead of returning the distinct elements in one shot? That way, it fits in well with the "lazy" evaluation semantics of IEnumerable<t> (like when items actually enumerates over the contents of a file, for example). Something like
public static IEnumerable<T> Distinct<T>(IEnumerable<T> items)
{
Queue<T> distinct = new Queue<T>();
foreach (T element in items)
{
if (!distinct.Contains(element))
{
distinct.Enqueue(element);
yield return element;
}
}
}
If the caller stops with the first two distinct elements, for example, then this saves a lot of needless computation.
|
|
|
|
|
Yes, good catch, Senthil. I'm a big fan of yield return -- I'm surprised I didn't catch it myself. Thanks.
|
|
|
|
|
Hi,
I am getting weird error while trying to check whether this xml document is well form or not.
Error I am getting is only for the xml file who has external dtd defined. If xml file requires a schema or inline dtd... it works perfectly fine. I tested this xml file with Stylus Studio Xml Editor and it works perfectly fine and validates the MessageExternalDTD.xml file. In my case the error it says is "Could not find file 'C:\Documents and Settings\ronak.patel\Local Settings\Temp\message.dtd'. Even though dtd file is at the same location as the xml file is.
One thing i understand from this error during validating or checking wellformness xml file requires dtd or xsd files to be present at "C:\Documents and Settings\ronak.patel\Local Settings\Temp\" directory. If they are there and not in the same directory where xml file is still it would work, but not vice versa.
MessageExternalDTD.xml
<message>
<to>Dave
<from>Susan
<subject>Reminder
<text>Don't forget to buy milk on the way home!
message.dtd
Here is my Code...
XmlDocument xmlDocument = xmlData.xmlDocument;
//xmlDocument is already given to me..
MemoryStream mstream = new MemoryStream();
StreamWriter writer = new StreamWriter(mstream);
xmlDocument.Save(mstream);
mstream.Seek(0, SeekOrigin.Begin);
try
{
while (reader.Read())
{
}
}
catch (XmlException ex)
{
MessageBox("XML Error : " + ex.Message);
m_success = false;
}
catch (Exception exe)
{
MessageBox("Error : " + exe.Message);
m_success = false;
}
finally
{
if (!m_success)
{
MessageBox.Show("Not Well Form");
}
else
{
MessageBox.Show("Well Form");
}
m_success = true;
reader.close();
}
|
|
|
|
|
Hi,
Can any one give me example of site where i can use
WebClient.DownloadFile(url,localfile); with Credentials...supplied to Webclient
like this
NetworkCredential auth = new NetworkCredential(tbUsername.Text, tbpassword.Text);
client.Credentials = auth;
I tried with so many sites but still no luck. Basically i want to download file from a website which asks for user credentials which i can pass to WebClient object.
|
|
|
|
|
Hi,
I am doing Http Get and Post operation using WebClient class of System.Net.
Is there a way to block cookies while i am doing this operations?
|
|
|
|
|
Hi,
I have working code of above function in vc++. I need help to convert it to c#....Any one know how to achieve this in c# please help me out here.
The code i got is from this link....
http://www.codeproject.com/dll/Execute_DLL_Function.asp
bool GetDLLFileExports(char *szFileName, unsigned int *nNoOfExports, char **&pszFunctions)
{
HANDLE hFile;
HANDLE hFileMapping;
LPVOID lpFileBase;
PIMAGE_DOS_HEADER pImg_DOS_Header;
PIMAGE_NT_HEADERS pImg_NT_Header;
PIMAGE_EXPORT_DIRECTORY pImg_Export_Dir;
hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if(hFile == INVALID_HANDLE_VALUE)
return false;
hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if(hFileMapping == 0)
{
CloseHandle(hFile);
return false;
}
lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if(lpFileBase == 0)
{
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_DOS_Header = (PIMAGE_DOS_HEADER)lpFileBase;
pImg_NT_Header = (PIMAGE_NT_HEADERS)((LONG)pImg_DOS_Header + (LONG)pImg_DOS_Header->e_lfanew);
if(IsBadReadPtr(pImg_NT_Header, sizeof(IMAGE_NT_HEADERS))||pImg_NT_Header->Signature != IMAGE_NT_SIGNATURE)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir = (PIMAGE_EXPORT_DIRECTORY)pImg_NT_Header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
if(!pImg_Export_Dir)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
pImg_Export_Dir= (PIMAGE_EXPORT_DIRECTORY)ImageRvaToVa(pImg_NT_Header,pImg_DOS_Header, (DWORD)pImg_Export_Dir, 0);
DWORD **ppdwNames = (DWORD **)pImg_Export_Dir->AddressOfNames;
ppdwNames = (PDWORD*)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)ppdwNames, 0);
if(!ppdwNames)
{
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return false;
}
*nNoOfExports = pImg_Export_Dir->NumberOfNames;
pszFunctions = new char*[*nNoOfExports];
for(unsigned i=0; i < *nNoOfExports; i++)
{
char *szFunc=(PSTR)ImageRvaToVa(pImg_NT_Header, pImg_DOS_Header, (DWORD)*ppdwNames, 0);
pszFunctionsIdea = new char[strlen(szFunc)+1];
strcpy(pszFunctionsIdea,szFunc);
ppdwNames++;
}
UnmapViewOfFile(lpFileBase);
CloseHandle(hFileMapping);
CloseHandle(hFile);
return true;
};
|
|
|
|
|
I'm rewriting a project from C++(MFC) to C#, mostly to learn this new language. In that project I use CAsyncSocket to create a TCP connection with another peer in a network to send some notification messages or some very small amount of data or a requests.
I tried to find a similar easy way to implement an asynchronous TCP connection in C#, but most of them are not.
Is there any alternative to that in C#? Is there any component or namespace or class that can help me do it quickly?
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|
|
System.Net.Socket namespace?
only two letters away from being an asset
|
|
|
|
|
Thanks Mark.
Mark Nischalke wrote: only two letters away from being an asset
// "Life is very short and is very fragile also." Yanni while (I'm_alive) { cout<<"I love programming."; }
|
|
|
|