//[TestMethod] public void JsonToXlsxTest() { const string sourceFilePath = @"path"; string resultPath = Path.Combine( Path.GetDirectoryName(sourceFilePath), Path.GetFileNameWithoutExtension(sourceFilePath) + DateTime.Now.ToString("dd.MM.yyyy_HH.mm.ss") + ".xlsx"); string json = File.ReadAllText(sourceFilePath, Encoding.UTF8); JsonToXlsxConverter.SaveAs(json, resultPath); }
//[TestMethod] public void XlsxToJsonTest() { string filePath = @"path"; JArray jObject = JsonToXlsxConverter.XlsxToJson(filePath); File.WriteAllText( Path.Combine( Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath) + ".json"), JsonConvert.SerializeObject( jObject, Formatting.Indented)); }
static void JsonToXlsx() { var cvt = new JsonToXlsxConverter(); string configJson = File.ReadAllText("config.json"); var config = JObject.Parse(configJson); string masterJsonPath = config["JsonToXlsx"].Value <string>("MasterJson"); string[] slaveJsonPaths = config["JsonToXlsx"]["SlaveJson"].ToObject <string[]>(); string outputDir = config["JsonToXlsx"].Value <string>("OutputDir"); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } using (var stream = cvt.GetXlsxFileAsync(masterJsonPath, slaveJsonPaths).GetAwaiter().GetResult()) { string outputPath = Path.Combine(outputDir, "result.xlsx"); File.WriteAllBytes(outputPath, stream.ToArray()); } }