Click here to Skip to main content
15,892,005 members
Articles / Desktop Programming / Windows Forms

ResxWriter: Generating .resx files from an Excel spreadsheet

Rate me:
Please Sign up or sign in to vote.
4.94/5 (22 votes)
17 Nov 20062 min read 131.6K   3.5K   65  
Generate .resx files from an Excel spreadsheet; fully customizable.
/*
 * Patrick Bounaix
 * www.L0g1c4L.com
 * 
 * See AssemblyInfo.cs 
 * for License Information
 * */

#region using
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
#endregion

namespace L0g1c4L.ResxWriter.UI
{
	/// <summary>
	/// Summary description for FrmManageColumns.
	/// </summary>
	public class FrmManageColumns : System.Windows.Forms.Form
	{
		#region Private...
		#region Properties
		private System.Windows.Forms.TextBox tbControl;
		private System.Windows.Forms.Button btOk;
		private System.Windows.Forms.Label lbControl;
		private System.Windows.Forms.Label lbEnglish;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btAdd;
		private System.Windows.Forms.Button btCancel;
		private System.Windows.Forms.ToolTip toolTip1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox tbSheet;
		private System.Windows.Forms.Button btDefault;
		private System.Windows.Forms.CheckedListBox clbLanguages;
		private System.Windows.Forms.Button btRemove;
		private System.ComponentModel.IContainer components;
		#endregion

		#region Methods
		#region Dispose
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FrmManageColumns));
			this.tbControl = new System.Windows.Forms.TextBox();
			this.btOk = new System.Windows.Forms.Button();
			this.lbControl = new System.Windows.Forms.Label();
			this.lbEnglish = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.btAdd = new System.Windows.Forms.Button();
			this.btCancel = new System.Windows.Forms.Button();
			this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
			this.tbSheet = new System.Windows.Forms.TextBox();
			this.btDefault = new System.Windows.Forms.Button();
			this.btRemove = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.clbLanguages = new System.Windows.Forms.CheckedListBox();
			this.SuspendLayout();
			// 
			// tbControl
			// 
			this.tbControl.Location = new System.Drawing.Point(24, 112);
			this.tbControl.MaxLength = 50;
			this.tbControl.Name = "tbControl";
			this.tbControl.Size = new System.Drawing.Size(248, 26);
			this.tbControl.TabIndex = 2;
			this.tbControl.Text = "";
			this.toolTip1.SetToolTip(this.tbControl, "Enter the Control Column Name here.");
			// 
			// btOk
			// 
			this.btOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btOk.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btOk.Location = new System.Drawing.Point(120, 464);
			this.btOk.Name = "btOk";
			this.btOk.Size = new System.Drawing.Size(72, 40);
			this.btOk.TabIndex = 5;
			this.btOk.Text = "OK";
			this.toolTip1.SetToolTip(this.btOk, "Click to save current Control and Language Column\'s.");
			this.btOk.Click += new System.EventHandler(this.btOk_Click);
			// 
			// lbControl
			// 
			this.lbControl.Location = new System.Drawing.Point(39, 80);
			this.lbControl.Name = "lbControl";
			this.lbControl.Size = new System.Drawing.Size(214, 23);
			this.lbControl.TabIndex = 2;
			this.lbControl.Text = "Control Column Name";
			this.lbControl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// lbEnglish
			// 
			this.lbEnglish.Location = new System.Drawing.Point(26, 160);
			this.lbEnglish.Name = "lbEnglish";
			this.lbEnglish.Size = new System.Drawing.Size(240, 23);
			this.lbEnglish.TabIndex = 5;
			this.lbEnglish.Text = "Language Column Names";
			this.lbEnglish.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// groupBox1
			// 
			this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.groupBox1.Location = new System.Drawing.Point(24, 448);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(248, 3);
			this.groupBox1.TabIndex = 8;
			this.groupBox1.TabStop = false;
			// 
			// btAdd
			// 
			this.btAdd.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btAdd.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btAdd.Location = new System.Drawing.Point(24, 368);
			this.btAdd.Name = "btAdd";
			this.btAdd.Size = new System.Drawing.Size(248, 32);
			this.btAdd.TabIndex = 4;
			this.btAdd.Text = "Add New Language Column";
			this.toolTip1.SetToolTip(this.btAdd, "Click to add a new Language Column entry.");
			this.btAdd.Click += new System.EventHandler(this.btAdd_Click);
			// 
			// btCancel
			// 
			this.btCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btCancel.Location = new System.Drawing.Point(200, 464);
			this.btCancel.Name = "btCancel";
			this.btCancel.Size = new System.Drawing.Size(72, 40);
			this.btCancel.TabIndex = 6;
			this.btCancel.Text = "Cancel";
			this.toolTip1.SetToolTip(this.btCancel, "Click to cancel.");
			this.btCancel.Click += new System.EventHandler(this.btCancel_Click);
			// 
			// tbSheet
			// 
			this.tbSheet.Location = new System.Drawing.Point(24, 40);
			this.tbSheet.MaxLength = 50;
			this.tbSheet.Name = "tbSheet";
			this.tbSheet.Size = new System.Drawing.Size(248, 26);
			this.tbSheet.TabIndex = 1;
			this.tbSheet.Text = "";
			this.toolTip1.SetToolTip(this.tbSheet, "Enter the sheet name here. (NOTE: \'$\'s are added automatically for Sheet name.)");
			// 
			// btDefault
			// 
			this.btDefault.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btDefault.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btDefault.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btDefault.Location = new System.Drawing.Point(24, 464);
			this.btDefault.Name = "btDefault";
			this.btDefault.Size = new System.Drawing.Size(88, 40);
			this.btDefault.TabIndex = 18;
			this.btDefault.Text = "Default Settings";
			this.toolTip1.SetToolTip(this.btDefault, "Click to restore default settings.");
			this.btDefault.Click += new System.EventHandler(this.btDefault_Click);
			// 
			// btRemove
			// 
			this.btRemove.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
			this.btRemove.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btRemove.ForeColor = System.Drawing.Color.Red;
			this.btRemove.Location = new System.Drawing.Point(24, 408);
			this.btRemove.Name = "btRemove";
			this.btRemove.Size = new System.Drawing.Size(248, 32);
			this.btRemove.TabIndex = 20;
			this.btRemove.Text = "Remove Selected Language Column\'s";
			this.toolTip1.SetToolTip(this.btRemove, "Click to remove selected Language Column entries.");
			this.btRemove.Click += new System.EventHandler(this.btRemove_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(40, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(214, 23);
			this.label1.TabIndex = 17;
			this.label1.Text = "Sheet Name";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// clbLanguages
			// 
			this.clbLanguages.CheckOnClick = true;
			this.clbLanguages.HorizontalScrollbar = true;
			this.clbLanguages.Location = new System.Drawing.Point(24, 184);
			this.clbLanguages.Name = "clbLanguages";
			this.clbLanguages.Size = new System.Drawing.Size(248, 172);
			this.clbLanguages.TabIndex = 19;
			// 
			// FrmManageColumns
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(7, 19);
			this.ClientSize = new System.Drawing.Size(292, 514);
			this.ControlBox = false;
			this.Controls.Add(this.btRemove);
			this.Controls.Add(this.clbLanguages);
			this.Controls.Add(this.btDefault);
			this.Controls.Add(this.tbSheet);
			this.Controls.Add(this.tbControl);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btCancel);
			this.Controls.Add(this.btAdd);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.lbEnglish);
			this.Controls.Add(this.lbControl);
			this.Controls.Add(this.btOk);
			this.Font = new System.Drawing.Font("Tahoma", 11.25F);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "FrmManageColumns";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "ResxWriter - Manage SpreadSheet Data";
			this.toolTip1.SetToolTip(this, "Manage the spreadsheet columns from here.");
			this.Load += new System.EventHandler(this.FrmManageColumns_Load);
			this.ResumeLayout(false);

		}
		#endregion				

		#region btOk_Click
		private void btOk_Click(object sender, System.EventArgs e)
		{
			if ((this.tbControl.Text.Length == 0) || (this.tbSheet.Text.Length == 0))
			{
				FrmMessage m = new FrmMessage();
				m.SetMessageText("ResxWriter - Error Message", 
					"Sheet and Control column MUST be specified!");
				m.ShowDialog();				
			}
			else
			{
				// sheet must end in $- i found out the hard way! //
				if (this.tbSheet.Text.LastIndexOf('$') != this.tbSheet.Text.Length-1)
				{
					this.tbSheet.Text += "$";
				}

				ClsMain.settings.SheetName = this.tbSheet.Text;
				ClsMain.settings.ControlColumnName = this.tbControl.Text;
				this.Close();
			}
		}
		#endregion		

		#region FrmManageColumns_Load
		private void FrmManageColumns_Load(object sender, System.EventArgs e)
		{
			LoadData();			
		}
		#endregion

		#region LoadData
		private void LoadData()
		{
			this.tbSheet.Text = ClsMain.settings.SheetName;
			this.tbControl.Text = ClsMain.settings.ControlColumnName;				
			
			this.clbLanguages.Items.Clear();
			foreach (ClsLanguage l in ClsMain.settings.LanguageCollection)
			{				
				this.clbLanguages.Items.Add(l);
			}
		}
		#endregion

		#region btAdd_Click
		private void btAdd_Click(object sender, System.EventArgs e)
		{
			FrmAddColumn add = new FrmAddColumn();
			if (add.ShowDialog() == DialogResult.OK)
			{				
				this.LoadData();
			}
		}
		#endregion

		#region btCancel_Click
		private void btCancel_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		#endregion					

		#region btDefault_Click
		private void btDefault_Click(object sender, System.EventArgs e)
		{
			if (MessageBox.Show("Restore Default Settings?", "ResxWriter",
				MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
			{
				ClsMain.manager.SetDefaultSettings();
				this.LoadData();
			}
		}
		#endregion

		private void btRemove_Click(object sender, System.EventArgs e)
		{
			if (this.clbLanguages.CheckedItems.Count > 0)
			{
				if (MessageBox.Show("Remove selected language columns?", "ResxWriter", 
					MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{											
					foreach (ClsLanguage o in this.clbLanguages.CheckedItems)
					{
						ClsMain.settings.LanguageCollection.Remove(o);
					}

					this.LoadData();					
				}
			}
		}
		#endregion
		#endregion

		#region Public...
		#region Constructor
		/// <summary>
		/// Default Constructor.
		/// </summary>
		public FrmManageColumns()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();										
		}	
		#endregion				
		#endregion			
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
- philosophy
- french
- computer science

Comments and Discussions