Skip to content

Commit 3a7a5b8

Browse files
tduguidtduguid
authored andcommitted
Updated the ribbon button Date Format to execute only on column from active cell
1 parent 0f95f73 commit 3a7a5b8

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

CS/Scripts/Ribbon.cs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ public void FormatDateColumns()
818818
{
819819
Excel.ListObject tbl = null;
820820
Excel.Range cell = null;
821+
Excel.Range cellCurrent = null;
821822
try
822823
{
823824
if (ErrorHandler.IsAvailable(true) == false)
@@ -827,17 +828,16 @@ public void FormatDateColumns()
827828
ErrorHandler.CreateLogRecord();
828829
tbl = Globals.ThisAddIn.Application.ActiveCell.ListObject;
829830
cell = default(Excel.Range);
831+
cellCurrent = Globals.ThisAddIn.Application.ActiveCell;
832+
int columnIndex = cellCurrent.Column;
830833
Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
831834
foreach (Excel.ListColumn col in tbl.ListColumns)
832835
{
833836
cell = FirstNotNullCellInColumn(col.DataBodyRange);
834-
if (((cell != null)))
837+
if (((col.Index == columnIndex)))
835838
{
836-
if (cell.NumberFormat.ToString() == Properties.Settings.Default.Table_ColumnFormatTime | ErrorHandler.IsDate(cell.Value))
837-
{
838-
col.DataBodyRange.NumberFormat = Properties.Settings.Default.Table_ColumnFormatDate;
839-
col.DataBodyRange.HorizontalAlignment = Excel.Constants.xlCenter;
840-
}
839+
col.DataBodyRange.NumberFormat = Properties.Settings.Default.Table_ColumnFormatDate;
840+
col.DataBodyRange.HorizontalAlignment = Excel.Constants.xlCenter;
841841
}
842842
}
843843
}
@@ -885,11 +885,8 @@ public void FormatTimeColumns()
885885
cell = FirstNotNullCellInColumn(col.DataBodyRange);
886886
if (((col.Index == columnIndex)))
887887
{
888-
//if (cell.NumberFormat.ToString() == Properties.Settings.Default.Table_ColumnFormatTime | ErrorHandler.IsTime(cell.Value))
889-
//{
890-
col.DataBodyRange.NumberFormat = Properties.Settings.Default.Table_ColumnFormatTime;
891-
col.DataBodyRange.HorizontalAlignment = Excel.Constants.xlCenter;
892-
//}
888+
col.DataBodyRange.NumberFormat = Properties.Settings.Default.Table_ColumnFormatTime;
889+
col.DataBodyRange.HorizontalAlignment = Excel.Constants.xlCenter;
893890
}
894891
}
895892
}

0 commit comments

Comments
 (0)