public static GetRandomDate ( int yearMin, int yearMax ) : System.DateTime | ||
yearMin | int | |
yearMax | int | |
Результат | System.DateTime |
internal static byte[] CreatePDF(int minKB, int maxKB) { PdfDocument pdfDoc = new PdfDocument(); pdfDoc.Info.Title = "SPDG created document"; pdfDoc.Info.Author = "SPDG"; pdfDoc.Info.Subject = "Sample SharePoint document"; PdfPage page = pdfDoc.AddPage(); page.Orientation = PdfSharp.PageOrientation.Portrait; XGraphics gfx = XGraphics.FromPdfPage(page); DrawText(gfx, 30, 30, page.Width, 20, XFontStyle.Bold, 20, SampleData.GetSampleValueRandom(SampleData.BusinessDocsTypes)); DrawText(gfx, 30, 60, page.Width, 20, XFontStyle.Regular, 12, "Date: " + SampleData.GetRandomDate(1990, 2015).ToShortDateString()); DrawText(gfx, 30, 80, page.Width, 20, XFontStyle.Regular, 12, "Author: " + SampleData.GetSampleValueRandom(SampleData.FirstNames) + " " + SampleData.GetSampleValueRandom(SampleData.LastNames)); DrawText(gfx, 30, 100, page.Width - 60, 20, XFontStyle.Regular, 12, "ID: " + SampleData.GetRandomNumber(100000, 1000000).ToString()); string lore = File.ReadAllText("SampleData\\loreIpsum.txt"); DrawText(gfx, 30, 120, page.Width, page.Height - 100, XFontStyle.Regular, 12, lore); gfx.Dispose(); int minRepeat = minKB / 13; int maxRepeat = maxKB / 13; int finalRepeat = 1; if (minRepeat > 20 && maxRepeat > 20 && minRepeat < maxKB) { finalRepeat = SampleData.GetRandomNumber(minRepeat, maxRepeat); } for (int i = 0; i < finalRepeat; i++) { page = pdfDoc.AddPage(); page.Orientation = PdfSharp.PageOrientation.Portrait; gfx = XGraphics.FromPdfPage(page); DrawText(gfx, 30, 30, page.Width - 60, page.Height - 100, XFontStyle.Regular, 12, lore); gfx.Dispose(); } MemoryStream memoryStream = new MemoryStream(); pdfDoc.Save(memoryStream); return(memoryStream.ToArray()); }
public static byte[] CreateDocx() { string text = File.ReadAllText("SampleData\\document.xml"); text = text.Replace("SPDGTitle", SampleData.GetSampleValueRandom(SampleData.BusinessDocsTypes)); text = text.Replace("SPDGDate", "Date: " + SampleData.GetRandomDate(1990, 2015).ToShortDateString()); text = text.Replace("SPDGUser", "Author: " + SampleData.GetSampleValueRandom(SampleData.FirstNames) + " " + SampleData.GetSampleValueRandom(SampleData.LastNames)); text = text.Replace("SPDGIdentity", "ID: " + SampleData.GetRandomNumber(100000, 1000000).ToString()); string lorem = File.ReadAllText("SampleData\\loreIpsum.txt"); text = text.Replace("SPDGLoreIpsum", getMultipleLoremIpsum(lorem, 1)); File.WriteAllText("SampleData\\SampleDocx\\word\\document.xml", text); string path = "SampleData\\SampleDocx"; using (ZipFile zip = new ZipFile()) { zip.AddFile(path + "\\[Content_Types].xml", string.Empty); zip.AddFile(path + "\\_rels\\.rels", "_rels"); zip.AddFile(path + "\\docProps\\app.xml", "docProps"); zip.AddFile(path + "\\docProps\\core.xml", "docProps"); zip.AddFile(path + "\\word\\_rels\\document.xml.rels", "word\\_rels"); zip.AddFile(path + "\\word\\theme\\theme1.xml", "word\\theme"); zip.AddFile(path + "\\word\\document.xml", "word"); zip.AddFile(path + "\\word\\fontTable.xml", "word"); zip.AddFile(path + "\\word\\settings.xml", "word"); zip.AddFile(path + "\\word\\styles.xml", "word"); zip.AddFile(path + "\\word\\webSettings.xml", string.Empty); zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G"); MemoryStream stream = new MemoryStream(); zip.Save(stream); byte[] bytes = new byte[stream.Length]; bytes = stream.ToArray(); stream.Close(); return(bytes); } }
internal static byte[] CreateExcel() { string text = File.ReadAllText("SampleData\\sharedStrings.xml"); text = text.Replace("SPDGTitle", SampleData.GetSampleValueRandom(SampleData.BusinessDocsTypes)); text = text.Replace("SPDGDate", "Date: " + SampleData.GetRandomDate(1990, 2015).ToShortDateString()); text = text.Replace("SPDGAuthor", "Author: " + SampleData.GetSampleValueRandom(SampleData.FirstNames) + " " + SampleData.GetSampleValueRandom(SampleData.LastNames)); text = text.Replace("SPDGIdentity", "ID: " + SampleData.GetRandomNumber(100000, 1000000).ToString()); File.WriteAllText("SampleData\\SampleExcel\\xl\\sharedStrings.xml", text); string path = "SampleData\\SampleExcel"; using (ZipFile zip = new ZipFile()) { zip.AddFile(path + "\\[Content_Types].xml", string.Empty); zip.AddFile(path + "\\_rels\\.rels", "_rels"); zip.AddFile(path + "\\docProps\\app.xml", "docProps"); zip.AddFile(path + "\\docProps\\core.xml", "docProps"); zip.AddFile(path + "\\xl\\_rels\\workbook.xml.rels", "xl\\_rels"); zip.AddFile(path + "\\xl\\printerSettings\\printerSettings1.bin", "xl\\printerSettings"); zip.AddFile(path + "\\xl\\theme\\theme1.xml", "xl\\theme"); zip.AddFile(path + "\\xl\\worksheets\\_rels\\sheet1.xml.rels", "xl\\worksheets\\_rels"); zip.AddFile(path + "\\xl\\worksheets\\sheet1.xml", "xl\\worksheets"); zip.AddFile(path + "\\xl\\calcChain.xml", "xl"); zip.AddFile(path + "\\xl\\sharedStrings.xml", "xl"); zip.AddFile(path + "\\xl\\styles.xml", "xl"); zip.AddFile(path + "\\xl\\workbook.xml", "xl"); zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G"); MemoryStream stream = new MemoryStream(); zip.Save(stream); byte[] bytes = new byte[stream.Length]; bytes = stream.ToArray(); stream.Close(); return(bytes); } }