public void AccessRichTextTest1() { IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLCell cell = ws.Cell(1, 1); cell.RichText.AddText("12"); cell.DataType = XLCellValues.Number; Assert.AreEqual(12.0, cell.GetDouble()); IXLRichText richText = cell.RichText; Assert.AreEqual("12", richText.ToString()); richText.AddText("34"); Assert.AreEqual("1234", cell.GetString()); Assert.AreEqual(XLCellValues.Number, cell.DataType); Assert.AreEqual(1234.0, cell.GetDouble()); }
public void AddTextTest3() { IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLCell cell = ws.Cell(1, 1); Int32 number = 123; cell.Value = number; cell.Style .Font.SetBold() .Font.SetFontColor(XLColor.Red); string text = number.ToString(); Assert.AreEqual(cell.RichText.ToString(), text); Assert.AreEqual(cell.RichText.First().Bold, true); Assert.AreEqual(cell.RichText.First().FontColor, XLColor.Red); Assert.AreEqual(1, cell.RichText.Count); cell.RichText.AddText("World"); Assert.AreEqual(cell.RichText.First().Text, text, "Item in collection is not the same as the one returned"); }
public void ToStringTest() { var ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLAddress address = ws.Cell(1, 1).Address; Assert.AreEqual("A1", address.ToString()); Assert.AreEqual("A1", address.ToString(XLReferenceStyle.A1)); Assert.AreEqual("R1C1", address.ToString(XLReferenceStyle.R1C1)); Assert.AreEqual("A1", address.ToString(XLReferenceStyle.Default)); Assert.AreEqual("Sheet1!A1", address.ToString(XLReferenceStyle.Default, true)); Assert.AreEqual("A1", address.ToStringRelative()); Assert.AreEqual("Sheet1!A1", address.ToStringRelative(true)); Assert.AreEqual("$A$1", address.ToStringFixed()); Assert.AreEqual("$A$1", address.ToStringFixed(XLReferenceStyle.A1)); Assert.AreEqual("R1C1", address.ToStringFixed(XLReferenceStyle.R1C1)); Assert.AreEqual("$A$1", address.ToStringFixed(XLReferenceStyle.Default)); Assert.AreEqual("Sheet1!$A$1", address.ToStringFixed(XLReferenceStyle.A1, true)); Assert.AreEqual("Sheet1!R1C1", address.ToStringFixed(XLReferenceStyle.R1C1, true)); Assert.AreEqual("Sheet1!$A$1", address.ToStringFixed(XLReferenceStyle.Default, true)); }
public void MDetem() { IXLWorksheet ws = new XLWorkbook().AddWorksheet("Sheet1"); ws.Cell("A1").SetValue(2).CellRight().SetValue(4); ws.Cell("A2").SetValue(3).CellRight().SetValue(5); Object actual; ws.Cell("A5").FormulaA1 = "MDeterm(A1:B2)"; actual = ws.Cell("A5").Value; Assert.IsTrue(XLHelper.AreEqual(-2.0, (double)actual)); ws.Cell("A6").FormulaA1 = "Sum(A5)"; actual = ws.Cell("A6").Value; Assert.IsTrue(XLHelper.AreEqual(-2.0, (double)actual)); ws.Cell("A7").FormulaA1 = "Sum(MDeterm(A1:B2))"; actual = ws.Cell("A7").Value; Assert.IsTrue(XLHelper.AreEqual(-2.0, (double)actual)); }
public void ToStringTest() { IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLRichText richString = ws.Cell(1, 1).RichText; richString.AddText("Hello"); richString.AddText(" "); richString.AddText("World"); string expected = "Hello World"; string actual = richString.ToString(); Assert.AreEqual(expected, actual); richString.AddText("!"); expected = "Hello World!"; actual = richString.ToString(); Assert.AreEqual(expected, actual); richString.ClearText(); expected = String.Empty; actual = richString.ToString(); Assert.AreEqual(expected, actual); }
public void SetCellValueToRange() { var ws = new XLWorkbook().AddWorksheet("Sheet1"); ws.Cell("A1").SetValue(2) .CellRight().SetValue(3) .CellRight().SetValue(5) .CellRight().SetValue(7); var range = ws.Range("1:1"); ws.Cell("B2").Value = range; Assert.AreEqual(2, ws.Cell("B2").Value); Assert.AreEqual(3, ws.Cell("C2").Value); Assert.AreEqual(5, ws.Cell("D2").Value); Assert.AreEqual(7, ws.Cell("E2").Value); }
public void Substring_From_ThreeStrings_Mid1() { IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLRichText richString = ws.Cell(1, 1).RichText; richString.AddText("Good Morning"); richString.AddText(" my "); richString.AddText("neighbors!"); IXLFormattedText <IXLRichText> actual = richString.Substring(5, 10); Assert.AreEqual(2, actual.Count); Assert.AreEqual(5, richString.Count); // The text was split because of the substring Assert.AreEqual("Morning", actual.ElementAt(0).Text); Assert.AreEqual(" my", actual.ElementAt(1).Text); Assert.AreEqual("Good ", richString.ElementAt(0).Text); Assert.AreEqual("Morning", richString.ElementAt(1).Text); Assert.AreEqual(" my", richString.ElementAt(2).Text); Assert.AreEqual(" ", richString.ElementAt(3).Text); Assert.AreEqual("neighbors!", richString.ElementAt(4).Text); }
public void Substring_From_OneString_Start() { IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLRichText richString = ws.Cell(1, 1).RichText; richString.AddText("Hello"); IXLFormattedText <IXLRichText> actual = richString.Substring(0, 2); Assert.AreEqual(1, actual.Count); // substring was in one piece Assert.AreEqual(2, richString.Count); // The text was split because of the substring Assert.AreEqual("He", actual.First().Text); Assert.AreEqual("He", richString.First().Text); Assert.AreEqual("llo", richString.Last().Text); actual.First().SetBold(); Assert.AreEqual(true, ws.Cell(1, 1).RichText.First().Bold); Assert.AreEqual(false, ws.Cell(1, 1).RichText.Last().Bold); richString.Last().SetItalic(); Assert.AreEqual(false, ws.Cell(1, 1).RichText.First().Italic); Assert.AreEqual(true, ws.Cell(1, 1).RichText.Last().Italic); Assert.AreEqual(false, actual.First().Italic); richString.SetFontSize(20); Assert.AreEqual(20, ws.Cell(1, 1).RichText.First().FontSize); Assert.AreEqual(20, ws.Cell(1, 1).RichText.Last().FontSize); Assert.AreEqual(20, actual.First().FontSize); }
public void Substring_From_ThreeStrings_Start2() { IXLWorksheet ws = new XLWorkbook().Worksheets.Add("Sheet1"); IXLRichText richString = ws.Cell(1, 1).RichText; richString.AddText("Good Morning"); richString.AddText(" my "); richString.AddText("neighbors!"); IXLFormattedText <IXLRichText> actual = richString.Substring(0, 15); Assert.AreEqual(2, actual.Count); Assert.AreEqual(4, richString.Count); // The text was split because of the substring Assert.AreEqual("Good Morning", actual.ElementAt(0).Text); Assert.AreEqual(" my", actual.ElementAt(1).Text); Assert.AreEqual("Good Morning", richString.ElementAt(0).Text); Assert.AreEqual(" my", richString.ElementAt(1).Text); Assert.AreEqual(" ", richString.ElementAt(2).Text); Assert.AreEqual("neighbors!", richString.ElementAt(3).Text); actual.ElementAt(1).SetBold(); Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(0).Bold); Assert.AreEqual(true, ws.Cell(1, 1).RichText.ElementAt(1).Bold); Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(2).Bold); Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(3).Bold); richString.First().SetItalic(); Assert.AreEqual(true, ws.Cell(1, 1).RichText.ElementAt(0).Italic); Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(1).Italic); Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(2).Italic); Assert.AreEqual(false, ws.Cell(1, 1).RichText.ElementAt(3).Italic); Assert.AreEqual(true, actual.ElementAt(0).Italic); Assert.AreEqual(false, actual.ElementAt(1).Italic); richString.SetFontSize(20); Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(0).FontSize); Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(1).FontSize); Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(2).FontSize); Assert.AreEqual(20, ws.Cell(1, 1).RichText.ElementAt(3).FontSize); Assert.AreEqual(20, actual.ElementAt(0).FontSize); Assert.AreEqual(20, actual.ElementAt(1).FontSize); }
private static void Main(string[] args) { string DirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string DLLPath = @"C:\Program Files (x86)\Steam\steamapps\common\From The Depths\From_The_Depths_Data\Managed\Ftd"; string InputPath = DirectoryName; string Text0 = "DLLファイルを選択してください"; Console.WriteLine(Text0); OpenFileDialog OFD = new OpenFileDialog { Title = Text0, InitialDirectory = Path.GetDirectoryName(DLLPath), FileName = DLLPath, Filter = "dll files (*.dll)|*.dll|All files (*.*)|*.*" }; if (OFD.ShowDialog() == DialogResult.OK) { DLLPath = OFD.FileName; } Console.WriteLine(DLLPath); OFD.Dispose(); string Text1 = "翻訳ファイルを指定してください"; Console.WriteLine(Text1); OpenFileDialog SFD = new OpenFileDialog { Title = Text1, InitialDirectory = Path.GetDirectoryName(InputPath), FileName = InputPath, Filter = "xlsx files (*.xlsx)|*.xlsx|All files (*.*)|*.*" }; if (SFD.ShowDialog() == DialogResult.OK) { InputPath = SFD.FileName; } Console.WriteLine(InputPath); SFD.Dispose(); Console.WriteLine("キー入力で文字列の置き換えを開始します"); Console.ReadKey(); foreach (string FilePath in Directory.GetFiles(Path.GetDirectoryName(DLLPath), "*.dll")) { string FileName = Path.GetFileName(FilePath); Console.WriteLine(FileName + "の取得中"); try { File.Copy(FilePath, Path.Combine(DirectoryName, FileName), true); } catch { Console.WriteLine("使用中のファイル : " + FileName); } } AssemblyDefinition AssemblyDef = AssemblyDefinition.ReadAssembly(DLLPath, new ReaderParameters { ReadWrite = true }); IEnumerable <TypeDefinition> TypeDefList = AssemblyDef.Modules.SelectMany(x => x.Types); IXLWorksheet IXLW = new XLWorkbook(InputPath).Worksheet("Translation"); int RowNum = IXLW.LastRowUsed().RowNumber(); int LineCount = 0; while (LineCount < RowNum) { string NameSpaceName = IXLW.Cell(++LineCount, 1).GetValue <string>(); string TypeName = IXLW.Cell(++LineCount, 1).GetValue <string>(); string MethodName = IXLW.Cell(++LineCount, 1).GetValue <string>(); List <Instruction> InstructionList = GetInstructionList(LineCount, TypeDefList, NameSpaceName, TypeName, MethodName); if (InstructionList == null) { while (IXLW.Cell(++LineCount, 1).GetValue <string>() != "--") { if (LineCount > RowNum) { break; } } continue; } while (IXLW.Cell(++LineCount, 1).GetValue <string>() != "--") { int Index = IXLW.Cell(LineCount, 1).GetValue <int>(); string ReadText = IXLW.Cell(LineCount, 2).GetValue <string>(); string WriteText = IXLW.Cell(LineCount, 3).GetValue <string>(); if (ReadText == WriteText) { continue; } Instruction Ins = null; if (Index >= 0 && Index < InstructionList.Count) { Ins = InstructionList[Index]; } if (Ins == null || Ins.Operand.ToString() != ReadText) { //Error Console.WriteLine($"置き換えに失敗しました 行:[{LineCount}] NameSpace:[{NameSpaceName}] Type:[{TypeName}] Method:[{MethodName}] Text:[{WriteText}]\n"); ++ErrorCount; continue; } Ins.Operand = WriteText; ++SuccessCount; } } AssemblyDef.Write(); Console.WriteLine("\n置き換えた文字列の数 : " + SuccessCount); Console.WriteLine("エラー発生回数 : " + ErrorCount); Console.WriteLine("\n文字列の置き換えが完了しました キー入力で終了します"); Console.ReadKey(); }