public void WriteTaskHeaders(MSExcel2003XmlFile xmlFile, int tableIndex, bool isActive) { List <string> headers = GetHeaders(isActive); xmlFile.SetColumnWidths(tableIndex, headers.Select(h => GetHeaderWidth(h)).ToList()); xmlFile.AddHeaderRow(tableIndex, headers); }
public void MSExcel2003XmlFile_AddHeaderRow_GetHeaders() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_AddHeaderRow_GetHeaders.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string title = "title"; List <string> headers = new List <string>() { "Title", "Address", "Last Name" }; //act int tableIndex = xmlFile.AddWorksheet(title); xmlFile.AddHeaderRow(tableIndex, headers); List <string> savedHeaders = xmlFile.GetHeaders(tableIndex); List <int> savedHeaderIndexes = headers.Select(h => xmlFile.GetHeaderIndex(tableIndex, h)).ToList(); string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); //assert Assert.AreEqual(headers.Count, savedHeaders.Count); Assert.AreEqual(headers.Count, savedHeaderIndexes.Count); for (int i = 0; i < headers.Count; i++) { Assert.AreEqual(headers[i], savedHeaders[i]); Assert.AreEqual(i, savedHeaderIndexes[i]); } Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_AddWorksheet_GetTableIndex() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_AddWorksheet.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string title0 = "A"; string title1 = "B"; string title2 = "C"; //act xmlFile.AddWorksheet(title0); xmlFile.AddWorksheet(title1); xmlFile.AddWorksheet(title2); int index0 = xmlFile.GetTableIndex(title0); int index1 = xmlFile.GetTableIndex(title1); int index2 = xmlFile.GetTableIndex(title2); int indexNone = xmlFile.GetTableIndex("D"); string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); //assert Assert.AreEqual(0, index0); Assert.AreEqual(1, index1); Assert.AreEqual(2, index2); Assert.AreEqual(-1, indexNone); Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void WriteTo(MSExcel2003XmlFile xmlFile) { int tableIndex = xmlFile.AddWorksheet(SHEET_NAME); xmlFile.AddHeaderRow(tableIndex, new List <string>() { STATUS_NAME, ACTIVE_NAME, "", CATEGORY_NAME, "", ID_NAME }); List <XmlNode> statusNodes = Statuses.Select(status => xmlFile.GenerateTextCell(status.Name)).ToList(); List <XmlNode> activeNodes = Statuses.Select(status => xmlFile.GenerateTextCell((status.Active ? "Active" : "Inactive"))).ToList(); //todo: make constants, but not connected to table names List <XmlNode> categoryNodes = Categories.Select(category => xmlFile.GenerateTextCell(category)).ToList(); xmlFile.AddColumns(tableIndex, new List <List <XmlNode> >() { statusNodes, activeNodes, new List <XmlNode>(), categoryNodes, new List <XmlNode>(), new List <XmlNode>() { xmlFile.GenerateNumberCell(MaxId) } }); }
public void WriteTo(MSExcel2003XmlFile xmlFile) { int tableIndex = xmlFile.AddWorksheet(GetSheetName()); columnLayout.WriteTaskHeaders(xmlFile, tableIndex, isActive); foreach (Task task in Tasks) { columnLayout.WriteTask(xmlFile, tableIndex, task, isActive); } }
public void MSExcel2003XmlFile_DefaultFile() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_Default.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); //act string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_GenerateEmptyCell() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_EmptyCell.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); //act XmlNode node = xmlFile.GenerateEmptyCell(); string text = XmlDocumentHelper.XmlToString(node); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_GenerateCell_Integer() { //arrange int data = 123; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); //act XmlNode nodeA = xmlFile.GenerateCell(data); XmlNode nodeB = xmlFile.GenerateNumberCell(data); string textA = XmlDocumentHelper.XmlToString(nodeA); string textB = XmlDocumentHelper.XmlToString(nodeB); //assert Assert.AreEqual(textA, textB); }
public void MSExcel2003XmlFile_GenerateTextCell_Style() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_TextCell_StyleId.txt"; string t = "abc"; string styleId = "italic"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); //act XmlNode node = xmlFile.GenerateTextCell(t, styleId); string text = XmlDocumentHelper.XmlToString(node); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_RemoveStyle() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_RemoveStyle.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string styleId = "header"; //act xmlFile.RemoveStyle(styleId); string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_GenerateCell_String() { //arrange string data = "abc"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); //act XmlNode nodeA = xmlFile.GenerateCell(data); XmlNode nodeB = xmlFile.GenerateTextCell(data); string textA = XmlDocumentHelper.XmlToString(nodeA); string textB = XmlDocumentHelper.XmlToString(nodeB); //assert Assert.AreEqual(textA, textB); }
public void MSExcel2003XmlFile_GenerateCell_DateTime() { //arrange DateTime data = new DateTime(1999, 3, 2); MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); //act XmlNode nodeA = xmlFile.GenerateCell(data); XmlNode nodeB = xmlFile.GenerateDateCell(data); string textA = XmlDocumentHelper.XmlToString(nodeA); string textB = XmlDocumentHelper.XmlToString(nodeB); //assert Assert.AreEqual(textA, textB); }
public void MSExcel2003XmlFile_AddRow_GetRowValues() { //arrange MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string title = "title"; List <object> valuesA = new List <object>() { "abc", 123, new DateTime(1999, 3, 2) }; List <object> valuesB = new List <object>() { "def", 456, new DateTime(1777, 5, 4) }; //act int tableIndex = xmlFile.AddWorksheet(title); xmlFile.AddRow(tableIndex, valuesA); xmlFile.AddRow(tableIndex, valuesB); List <string> savedValuesA = xmlFile.GetRowValues(tableIndex, 0); List <string> savedValuesB = xmlFile.GetRowValues(tableIndex, 1); int savedRowCount = xmlFile.GetRowCount(tableIndex); //assert Assert.AreEqual(valuesA.Count, savedValuesA.Count); for (int i = 0; i < valuesA.Count; i++) { if (valuesA[i] is DateTime) { Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValuesA[i]); } else { Assert.AreEqual(valuesA[i].ToString(), savedValuesA[i]); } } Assert.AreEqual(valuesB.Count, savedValuesB.Count); for (int i = 0; i < valuesB.Count; i++) { if (valuesB[i] is DateTime) { Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValuesB[i]); } else { Assert.AreEqual(valuesB[i].ToString(), savedValuesB[i]); } } Assert.AreEqual(2, savedRowCount); }
private void OpenProjectXML() { try { MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(FullPath); activeSheet = new TaskSheet(xmlFile, ACTIVE_SHEET_NAME, isActive: true); inactiveSheet = new TaskSheet(xmlFile, INACTIVE_SHEET_NAME, isActive: false); config = new ConfigSheet(xmlFile); } catch { CreateNewProject(); return; } }
private void SaveXML() { if (FileExtension.ToLower() != ".xml") { FullPath = FullPath.Replace(FileExtension, ".xml"); } MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); activeSheet.WriteTo(xmlFile); inactiveSheet.WriteTo(xmlFile); config.WriteTo(xmlFile); xmlFile.Save(FullPath); }
public void MSExcel2003XmlFile_GenerateDateTypeAttribute() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_DateTypeAttribute.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); XmlNode node = xmlFile.XmlDocument.CreateElement("A", xmlFile.XmlDocument.NamespaceURI); //act XmlAttribute attribute = xmlFile.GenerateDateTypeAttribute(); node.Attributes.Append(attribute); string text = XmlDocumentHelper.XmlToString(node); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public ConfigSheet(MSExcel2003XmlFile xmlFile) { int tableIndex = xmlFile.GetTableIndex(SHEET_NAME); if (tableIndex == -1) { Init(); return; } Statuses = new List <Status>(); List <string> statusValues = xmlFile.GetColumnValues(tableIndex, STATUS_NAME); List <string> isActiveValues = xmlFile.GetColumnValues(tableIndex, ACTIVE_NAME); if (statusValues == null || isActiveValues == null || statusValues.Count == 0 || isActiveValues.Count == 0) { SetDefaultStatuses(); } else { for (int i = 0; i < statusValues.Count; i++) { if (i >= isActiveValues.Count) { break; } Statuses.Add(new Status(statusValues[i], isActiveValues[i])); } } Categories = xmlFile.GetColumnValues(tableIndex, CATEGORY_NAME); if (Categories == null || Categories.Count == 0) { SetDefaultCategories(); } List <string> idValues = xmlFile.GetColumnValues(tableIndex, ID_NAME); if (idValues == null || idValues.Count == 0) { MaxId = DEFAULT_ID; } else { MaxId = Int32.Parse(idValues[0]); } }
public TaskSheet(MSExcel2003XmlFile xmlFile, string worksheetTitle, bool isActive) { Init(isActive); int tableIndex = xmlFile.GetTableIndex(worksheetTitle); if (tableIndex == -1) { return; } columnLayout = new ColumnLayout(xmlFile.GetRowValues(tableIndex, 0)); for (int rowIndex = 1; rowIndex < xmlFile.GetRowCount(tableIndex); rowIndex++) { Tasks.Add(new Task(xmlFile.GetRowValues(tableIndex, rowIndex), columnLayout)); } }
public void MSExcel2003XmlFile_AddStyle_Overwrite() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_AddStyle_Overwrite.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string styleId = "Header"; string childName = "ChildName"; string childAttributeName = "ChildAttributeName"; string childAttributeValue = "ChildAttributeValue"; //act xmlFile.AddStyle(styleId, childName, childAttributeName, childAttributeValue); string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void WriteTask(MSExcel2003XmlFile xmlFile, int tableIndex, Task task, bool isActive) { List <XmlNode> cellNodes = new List <XmlNode>() { xmlFile.GenerateNumberCell(task.Id), xmlFile.GenerateParagraphCell(task.Description), xmlFile.GenerateTextCell(task.Status), xmlFile.GenerateTextCell(task.Category), xmlFile.GenerateDateCell(task.CreateDate) }; if (!isActive && task.DoneDate.HasValue) { cellNodes.Add(xmlFile.GenerateDateCell(task.DoneDate.Value)); } xmlFile.AddRow(tableIndex, cellNodes); }
public void MSExcel2003XmlFile_SetColumnWidths() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_SetColumnWidths.txt"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string title = "title"; List <int> widths = new List <int>() { 20, 25, 10 }; //act int tableIndex = xmlFile.AddWorksheet(title); xmlFile.SetColumnWidths(tableIndex, widths); string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_GenerateAttribute_NewUri() { //arrange string comparisonFilename = "data/MSExcel2003XmlFile_Attribute_Uri.txt"; string prefix = "zz"; string uri = "google.com"; string name = "Bob"; string value = "100"; MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); XmlNode node = xmlFile.XmlDocument.CreateElement("A", xmlFile.XmlDocument.NamespaceURI); //act XmlAttribute attribute = xmlFile.GenerateAttribute(prefix, uri, name, value); node.Attributes.Append(attribute); string text = XmlDocumentHelper.XmlToString(node); //assert Assert.AreEqual(Utilities.LoadText(comparisonFilename), text); }
public void MSExcel2003XmlFile_AddColumns_GetColumnValues() { //arrange MSExcel2003XmlFile xmlFile = new MSExcel2003XmlFile(); string title = "title"; List <string> headers = new List <string>() { "A", "B", "C" }; List <object> valuesA = new List <object>() { "abc", 123, new DateTime(1999, 3, 2), 100 }; List <object> valuesB = new List <object>() { new DateTime(1777, 5, 4), "def", "ghijk", "lm", "nop", "qrstuv" }; List <object> valuesC = new List <object>() { 456, 400 }; List <List <object> > columns = new List <List <object> >() { valuesA, valuesB, valuesC }; int maxRowCount = Math.Max(valuesA.Count, Math.Max(valuesB.Count, valuesC.Count)); //act int tableIndex = xmlFile.AddWorksheet(title); xmlFile.AddHeaderRow(tableIndex, headers); xmlFile.AddColumns(tableIndex, columns); string text = XmlDocumentHelper.XmlToString(xmlFile.XmlDocument); List <string> savedValues0 = xmlFile.GetColumnValues(tableIndex, 0, firstRowIsHeader: true); List <string> savedValues1 = xmlFile.GetColumnValues(tableIndex, 1, firstRowIsHeader: true); List <string> savedValues2 = xmlFile.GetColumnValues(tableIndex, 2, firstRowIsHeader: true); List <string> savedValues0WithHeader = xmlFile.GetColumnValues(tableIndex, 0, firstRowIsHeader: false); List <string> savedValues1WithHeader = xmlFile.GetColumnValues(tableIndex, 1, firstRowIsHeader: false); List <string> savedValues2WithHeader = xmlFile.GetColumnValues(tableIndex, 2, firstRowIsHeader: false); List <string> savedValuesA = xmlFile.GetColumnValues(tableIndex, "A"); List <string> savedValuesB = xmlFile.GetColumnValues(tableIndex, "B"); List <string> savedValuesC = xmlFile.GetColumnValues(tableIndex, "C"); int savedColumnCount = xmlFile.GetColumnCount(tableIndex); //assert Assert.AreEqual(maxRowCount, savedValues0.Count); Assert.AreEqual(maxRowCount, savedValues1.Count); Assert.AreEqual(maxRowCount, savedValues2.Count); Assert.AreEqual(maxRowCount + 1, savedValues0WithHeader.Count); Assert.AreEqual(maxRowCount + 1, savedValues1WithHeader.Count); Assert.AreEqual(maxRowCount + 1, savedValues2WithHeader.Count); Assert.AreEqual(headers[0], savedValues0WithHeader[0]); Assert.AreEqual(headers[1], savedValues1WithHeader[0]); Assert.AreEqual(headers[2], savedValues2WithHeader[0]); for (int i = 0; i < valuesA.Count; i++) { if (valuesA[i] is DateTime) { Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValues0[i]); Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValues0WithHeader[i + 1]); Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesA[i]), savedValuesA[i]); } else { Assert.AreEqual(valuesA[i].ToString(), savedValues0[i]); Assert.AreEqual(valuesA[i].ToString(), savedValues0WithHeader[i + 1]); Assert.AreEqual(valuesA[i].ToString(), savedValuesA[i]); } } for (int i = 0; i < valuesB.Count; i++) { if (valuesB[i] is DateTime) { Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValues1[i]); Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValues1WithHeader[i + 1]); Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesB[i]), savedValuesB[i]); } else { Assert.AreEqual(valuesB[i].ToString(), savedValues1[i]); Assert.AreEqual(valuesB[i].ToString(), savedValues1WithHeader[i + 1]); Assert.AreEqual(valuesB[i].ToString(), savedValuesB[i]); } } for (int i = 0; i < valuesC.Count; i++) { if (valuesC[i] is DateTime) { Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesC[i]), savedValues2[i]); Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesC[i]), savedValues2WithHeader[i + 1]); Assert.AreEqual(MSExcel2003XmlFile.DateToString((DateTime)valuesC[i]), savedValuesC[i]); } else { Assert.AreEqual(valuesC[i].ToString(), savedValues2[i]); Assert.AreEqual(valuesC[i].ToString(), savedValues2WithHeader[i + 1]); Assert.AreEqual(valuesC[i].ToString(), savedValuesC[i]); } } Assert.AreEqual(3, savedColumnCount); }