Search This Blog
Wednesday, January 31, 2007
TFSBuildManager New Version
Enjoy.
Sunday, January 28, 2007
Export Data to Excel Sheet
I have notice that there is a lot of traffic to my Blog because of a post I have about exporting Excel chart to an image. I thought that it would be good to share more stuff about Excel automation in C#. Below you can find a method to export data into excel sheet. This function uses a list view as the data source.
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.Threading;
using System.Drawing;
using ExcelAutomation = Microsoft.Office.Interop.Excel;
namespace ExcelUtils
{
public static class Excel
{
private static void BorderAroundCell(ExcelAutomation.Range CellRange)
{
CellRange.BorderAround(ExcelAutomation.XlLineStyle.xlContinuous,
ExcelAutomation.XlBorderWeight.xlThin,
ExcelAutomation.XlColorIndex.xlColorIndexAutomatic,
Type.Missing);
}
public static void ReportFromListView(string reportName, ListView
listView)
{
ExcelAutomation.Application excelApp = new ExcelAutomation.ApplicationClass();
excelApp.UserControl = true;
CultureInfo oldCultureInfo = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
ExcelAutomation.Workbook workbook = excelApp.Workbooks.Add(Type.Missing);
ExcelAutomation.Worksheet worksheet = (ExcelAutomation.Worksheet)workbook.Worksheets.get_Item(1);
worksheet.Name = reportName;
//Headers
foreach (ColumnHeader columnHeader in listView.Columns)
{
worksheet.Cells[1, columnHeader.Index + 1] = columnHeader.Text;
}
string[] letters = new string[26]{"A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z"};
for (int i = 0; i < listView.Columns.Count; i++)
{
string headerCell = letters.GetValue(i) + "1";
worksheet.get_Range(headerCell, headerCell).Font.Bold = true;
BorderAroundCell(worksheet.get_Range(headerCell, headerCell));
worksheet.get_Range(headerCell, headerCell).Interior.ColorIndex = 36;
}
//Content
for (int i = 0; i < listView.Items.Count; i++)
{
for (int j = 0; j < listView.Columns.Count; j++)
{
string dataCell = letters.GetValue(j) + (i + 2).ToString();
worksheet.Cells[i + 2, j + 1] = listView.Items[i].SubItems[j].Text;
BorderAroundCell(worksheet.get_Range(dataCell, dataCell));
}
}
worksheet.Columns.AutoFit();
worksheet.Columns.HorizontalAlignment = ExcelAutomation.XlHAlign.xlHAlignLeft;
excelApp.Visible = true;
Thread.CurrentThread.CurrentCulture = oldCultureInfo;
}
}
}
Monday, January 22, 2007
New Terminals Version (Support for RDP 6.0)
We have published a new Terminals version (1.0 Prodcution). You can download it at here.
Here are the available changes for this release:
1. Support for RDP 6:
- 32bit color support.
- Supports screen resolutions of up to 4096x2048.
- Supports disabling clipboard redirection.
- Enable smart card redirection.
- Enable plug&play devices redirection.
2. Save position and size.
3. Nicer about box...
4. Execute before connect (per connection and for all connections).
5. Some additional bugs were fixed.
Enjoy.
Wednesday, January 17, 2007
Company Dashboard
Here are some pictures of the LCD screen:
Monday, January 15, 2007
5 Things That Will Make You Move To Vista
I don't think that moving to Vista is essential but I've decided to work with it and find out what will make me consider moving all of my machines to Vista.
So here are the first 5 features that made me smile:
- Start --> Run is dead. Start --> Start Search is the answer to those who won't leave their keyboards. Press the Windows button and start typing for searching programs and files. I did not open the programs group since I've installed Vista. It became useless.
- F2. This one made me smile the most. When you press F2 to rename a file the selected text is only the file name without the extension (for those of you that show file extensions). I wonder how long it took to develop this feature?
- Search is now part of the Explorer address bar. Just start typing and it show you the results in the same window. Performance is affected by indexing status.
- Burn button (Windows Explorer toolbar): Although I like using dedicated programs for CD/DVD burning I found the Burn button very useful. Select files and folders and press the Burn button to burn them.
- Restore previous versions (Folder, file context menu): If you will enable in system security Shadow Copies or System Restore you can get previous version of a file, folder. Good backup solution.
To be continued.
Wednesday, January 10, 2007
TFSBuildManager
Main features of this utility are:
- Start, stop a build
- Change build/s quality
- Delete, backup build/s
- Edit build type
I wrote it because I needed the ability to manage build types outside Visual Studio environment. Also, I needed some features that are not available through Visual Studio IDE.
I'm planning to add:
- Advanced build log
- Add new Build Type
- Build list filtering
- Edit advanced Build Type properties
Enjoy.
Monday, January 08, 2007
Export Excel Chart To Image
Here's the code to export the image:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using Excel = Microsoft.Office.Interop.Excel;
using System.Globalization;
using System.Threading;
using System.IO;
private static void ExportExcelChartToImage(string excelFile, string outputFile)
{
//Object to send in com methods instead of null
object missing = System.Reflection.Missing.Value;
//Create a new excel application
Excel.Application excelApplication = new Excel.ApplicationClass();
//Saving the old culture info
CultureInfo oldCultureInfo = Thread.CurrentThread.CurrentCulture;
try
{
//Setting new culture info is en-us is not default (Disable exception)
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-us");
//Open the excel document
Excel.Workbook excelWorkbook = excelApplication.Workbooks.Open(excelFile,
missing, missing, missing, missing, missing, missing, missing, missing,
missing, missing, missing, missing, missing, missing);
//Refresh the data from TFS
excelWorkbook.RefreshAll();
//Taking into consideration that there's only one sheet
Excel.Worksheet activeSheet = (Excel.Worksheet)excelWorkbook.ActiveSheet;
//Again, there's only one chart on the sheet
Excel.ChartObjects chartObjects = (Excel.ChartObjects)activeSheet.ChartObjects(missing);
Excel.ChartObject chartObject = (Excel.ChartObject)chartObjects.Item(1);
Excel.Chart chart = chartObject.Chart;
//Set the filter (bmp, jpg...)
string extension = Path.GetExtension(outputFile).Replace(".", "");
//Export the image
chart.Export(outputFile, extension, missing);
//Save and close the workbook
excelWorkbook.Save();
excelWorkbook.Close(false, excelFile, missing);
}
finally
{
//Set the old culture info
Thread.CurrentThread.CurrentCulture = oldCultureInfo;
//Close and free the excel application
excelApplication.Quit();
excelApplication = null;
}
}
Tuesday, January 02, 2007
Get List of Builds for Deleted Build Types
BuildData[] GetListOfBuilds(string teamProject, string buildType)
How to get build types list I have mentions in: How to Get Build Types List.
If you deleted a build type and you want to get list of builds from this type then you need to call GetListOfBuilds with String.Empty as the buildType parameter. This will return a full list of builds for the teamProject.
public BuildData[] GetAllBuilds(string server, string project)
{
TeamFoundationServer tfs = new TeamFoundationServer(server, CredentialCache.DefaultCredentials);
tfs.EnsureAuthenticated();
BuildStore bs = (BuildStore)tfs.GetService(typeof(BuildStore));
return bs.GetListOfBuilds(project, String.Empty);
}