public void CreateAllDirectories() { string basePath = @"C:\TempXLPath"; string folderName = "XLFolder"; var fileSystem = new VirtualFileSystem(); using (XLFile file = new XLFile(fileSystem, basePath, folderName)) { string folderPath = Path.Combine(basePath, folderName); file.SaveAs(@"C:\workbook.xlsx"); Assert.True(fileSystem.Directories.Contains(folderPath)); Assert.True(fileSystem.Directories.Contains(Path.Combine(folderPath, "_rels"))); Assert.True(fileSystem.Directories.Contains(Path.Combine(folderPath, "docProps"))); Assert.True(fileSystem.Directories.Contains(Path.Combine(folderPath, "xl"))); Assert.True(fileSystem.Directories.Contains(Path.Combine(folderPath, "xl", "_rels"))); Assert.True(fileSystem.Directories.Contains(Path.Combine(folderPath, "xl", "theme"))); Assert.True(fileSystem.Directories.Contains(Path.Combine(folderPath, "xl", "worksheets"))); Assert.Equal(7, fileSystem.Directories.Count); } }
private static void ExportWithSimpleXL() { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template.xlsx"); var tempBase = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tmp"); string basePath = Path.Combine(tempBase, Guid.NewGuid().ToString()); using (var file = new XLFile()) { file.ConfigureRange("A1:A2", new XLRangeConfig { Font = XLRangeFont.Bold, Border = true }); file.ConfigureRange("B1:B2", new XLRangeConfig { Font = XLRangeFont.Bold, Border = true, Format = XLRangeFormat.Number }); file.ConfigureRange("C1:C2", new XLRangeConfig { Format = XLRangeFormat.Percent }); file.WriteData(GetData()); file.SaveAs(basePath + ".xlsx"); } }
public Boolean validate(HTMLFile htmlFile, XLFile xlfile) { try { CellRange[] cells = xlfile.CellsFirstCol; Boolean check = true; for (int i = 1; i < cells.Length; i++) { if (!htmlFile.checkID(cells[i].Value.ToString())) { System.Console.Write("ID '" + cells[i].Value.ToString() + "' is missing\n"); check = false; } htmlFile.NodeList.Add(htmlFile.Htmldoc.GetElementbyId(cells[i].Value.ToString())); } return(check); } catch (Exception exc) { System.Console.Write(exc.StackTrace); } return(false); }
public void CreateAllFiles() { string basePath = @"C:\TempXLPath"; string folderName = "XLFolder"; var fileSystem = new VirtualFileSystem(); using (XLFile file = new XLFile(fileSystem, basePath, folderName)) { string folderPath = Path.Combine(basePath, folderName); string xlFile = @"C:\workbook.xlsx"; file.SaveAs(xlFile); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "xl", "sharedStrings.xml"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "xl", "styles.xml"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "xl", "workbook.xml"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "xl", "_rels", "workbook.xml.rels"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "xl", "theme", "theme1.xml"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "[Content_Types].xml"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "_rels", ".rels"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "docProps", "app.xml"))); Assert.True(fileSystem.Files.Contains(Path.Combine(folderPath, "docProps", "core.xml"))); Assert.Equal(9, fileSystem.Files.Count); } }
public void ConfigureInvalidRanges() { using (XLFile file = new XLFile(new VirtualFileSystem())) { Assert.Throws <ArgumentNullException>(() => file.ConfigureRange(null, null)); Assert.Throws <ArgumentNullException>(() => file.ConfigureRange(string.Empty, null)); Assert.Throws <ArgumentNullException>(() => file.ConfigureRange(" ", null)); Assert.Throws <ArgumentNullException>(() => file.ConfigureRange(null, new XLRangeConfig())); Assert.Throws <ArgumentNullException>(() => file.ConfigureRange(string.Empty, new XLRangeConfig())); Assert.Throws <ArgumentNullException>(() => file.ConfigureRange(" ", new XLRangeConfig())); Assert.Throws <ArgumentNullException>(() => file.ConfigureRange("A1:B1", null)); Assert.Throws <ArgumentException>(() => file.ConfigureRange(":", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("A", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("A:", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange(":A", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("A1:", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("A1:B", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("A:B1", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("AAAA1:B1", new XLRangeConfig())); Assert.Throws <ArgumentException>(() => file.ConfigureRange("A1:BAAAA1", new XLRangeConfig())); } }