Snip2Code is shutting down.
It has been quite a ride, since 2013 when we launched our first prototype: thanks to the effort of you guys we collected more than 3 million snippets!
We are very proud to help all our users to be more efficient in their jobs, and to be the central point to share programming knowledge for everyone.
Our basic service is free, so we always survived on our own resources to give you Snip2Code.
Unfortunately, we are no more in the financial position to sustain this effort, and therefore we are announcing here our permanent shut down,
which will take place on August 1st, 2020.
Please save your private snippets using our backup function in the settings, here.
IF YOU WANT TO SAVE SNIP2CODE, PLEASE CONSIDER DOING A DONATION!
This will allow us to pay for the servers and the infrastructure. If you want to donate, Contact Us!
by
0
5
2,298
1
Top 1% !
Famous
Tagged
Easy-to-find
Specified
Popularity: 8457th place
This snippet is Public
LanguageCSharp
LicenseMIT_X11

How to populate an Excel worksheet with data in CSharp

This c# example shows how to add some data into a worksheet in a Microsoft Excel document (xls). Note the hyperlink pointing to the main sheet.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/611/How-to-populate-an-Excel-worksheet-with-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/// <summary> /// Populate the Sheet /// </summary> /// <param name="ws">Worksheet</param> /// <param name="tc">SyncSSTestCase</param> private void populateXlsSheet(Worksheet ws, SyncSSTestCase tc) { ws.Name = tc.SheetName; int rowIndex = 1; ws.get_Range("A" + rowIndex, "A" + rowIndex).Cells.Value2 = "Test case Name"; ws.get_Range("A" + rowIndex, "A" + rowIndex).Cells.ColumnWidth = 30; ws.get_Range("B" + rowIndex, "B" + rowIndex).Cells.Value2 = "Purpose"; ws.get_Range("B" + rowIndex, "B" + rowIndex).Cells.ColumnWidth = 30; ws.get_Range("C" + rowIndex, "C" + rowIndex).Cells.Value2 = "Area"; ws.get_Range("C" + rowIndex, "C" + rowIndex).Cells.ColumnWidth = 15; ws.get_Range("D" + rowIndex, "D" + rowIndex).Cells.Value2 = "Entity"; ws.get_Range("E" + rowIndex, "D" + rowIndex).Cells.ColumnWidth = 15; ws.get_Range("E" + rowIndex, "E" + rowIndex).Cells.Value2 = "Type"; ws.get_Range("E" + rowIndex, "E" + rowIndex).Cells.ColumnWidth = 15; ws.get_Range("F" + rowIndex, "F" + rowIndex).Cells.Value2 = "Environment"; ws.get_Range("F" + rowIndex, "F" + rowIndex).Cells.ColumnWidth = 15; ws.get_Range("G" + rowIndex, "G" + rowIndex).Cells.Value2 = "Actions"; ws.get_Range("G" + rowIndex, "G" + rowIndex).Cells.ColumnWidth = 30; ws.get_Range("H" + rowIndex, "H" + rowIndex).Cells.Value2 = "Expected Behavior"; ws.get_Range("H" + rowIndex, "H" + rowIndex).Cells.ColumnWidth = 30; ws.get_Range("I" + rowIndex, "I" + rowIndex).Cells.Value2 = "Comments"; ws.get_Range("I" + rowIndex, "I" + rowIndex).Cells.ColumnWidth = 20; ws.get_Range("A" + rowIndex, "I" + rowIndex).Cells.Font.Color = ColorTranslator.ToWin32(Color.White); ws.get_Range("A" + rowIndex, "I" + rowIndex).Cells.Interior.Color = ColorTranslator.ToWin32(Color.Gray); ws.get_Range("A" + rowIndex, "I" + rowIndex).Cells.Font.Bold = true; rowIndex++; ws.get_Range("A" + rowIndex, "A" + rowIndex).Cells.Value2 = tc.FullName; ws.get_Range("B" + rowIndex, "B" + rowIndex).Cells.Value2 = tc.Purpose; ws.get_Range("C" + rowIndex, "C" + rowIndex).Cells.Value2 = tc.Area; ws.get_Range("D" + rowIndex, "D" + rowIndex).Cells.Value2 = tc.Entity; ws.get_Range("E" + rowIndex, "E" + rowIndex).Cells.Value2 = tc.Type; ws.get_Range("F" + rowIndex, "F" + rowIndex).Cells.Value2 = tc.Environment; string steps = string.Empty; int stepscount = 1; string envNewLine = Environment.NewLine; foreach (XmlNode step in tc.ActionSteps) { if (stepscount == tc.ActionSteps.Count) { envNewLine = ""; } steps += string.Format("Step {0}:{1}{2}", stepscount, step.InnerText, envNewLine); stepscount++; } ws.get_Range("G" + rowIndex, "G" + rowIndex).Cells.Value2 = steps; ws.get_Range("H" + rowIndex, "H" + rowIndex).Cells.Value2 = tc.ExpectedBehavior; ws.get_Range("I" + rowIndex, "I" + rowIndex).Cells.Value2 = tc.Comment; //Create link to Main Sheet Summary Report rowIndex += 2; ws.get_Range("A" + rowIndex, "A" + rowIndex).Cells.Value2 = string.Format("=HYPERLINK(\"#{0}!A1\",\"<< Go to " + c_mainsSheet_Name + "\")", c_mainsSheet_Name); }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus