diff --git a/index.json b/index.json index 148ce5d2de..5787907273 100644 --- a/index.json +++ b/index.json @@ -4,11 +4,111 @@ "language": "csharp", "framework": ".NET", "examples": [ + { + "category": "timeline", + "file": "add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs", + "title": "Add interactive hyperlinks to timeline markers that open related worksheets when the PDF is viewed." + }, + { + "category": "timeline", + "file": "apply-a-dark-theme-to-a-timeline-change-axis-colors-and-render-the-result-to-a-pdf.cs", + "title": "Apply a dark theme to a timeline, change axis colors, and render the result to a PDF." + }, + { + "category": "timeline", + "file": "apply-a-gradient-background-to-a-timeline-adjust-label-rotation-and-render-it-to-a-bmp-image.cs", + "title": "Apply a gradient background to a timeline, adjust label rotation, and render it to a BMP image." + }, + { + "category": "timeline", + "file": "apply-a-watermark-text-over-a-rendered-timeline-image-and-export-the-final-picture-as-a-pdf.cs", + "title": "Apply a watermark text over a rendered timeline image and export the final picture as a PDF." + }, + { + "category": "timeline", + "file": "apply-conditional-formatting-to-timeline-bars-based-on-performance-thresholds-and-export-the-result-as-a-pdf.cs", + "title": "Apply conditional formatting to timeline bars based on performance thresholds and export the result as a PDF." + }, + { + "category": "timeline", + "file": "batch-convert-excel-files-add-a-timeline-to-each-and-save-pdfs-to-an-output-directory.cs", + "title": "Batch convert Excel files, add a timeline to each, and save PDFs to an output directory." + }, + { + "category": "timeline", + "file": "batch-process-multiple-worksheets-creating-individual-timelines-for-each-and-saving-them-as-separate-png-files.cs", + "title": "Batch process multiple worksheets, creating individual timelines for each and saving them as separate PNG files." + }, + { + "category": "timeline", + "file": "combine-two-separate-timelines-into-a-single-composite-view-and-save-the-merged-chart-as-an-svg-file.cs", + "title": "Combine two separate timelines into a single composite view and save the merged chart as an SVG file." + }, + { + "category": "timeline", + "file": "create-a-timeline-using-a-custom-template-file-then-replace-placeholder-text-with-dynamic-project-names.cs", + "title": "Create a timeline using a custom template file, then replace placeholder text with dynamic project names." + }, + { + "category": "timeline", + "file": "create-a-timeline-with-a-logarithmic-scale-for-dates-customize-tick-intervals-and-render-to-png.cs", + "title": "Create a timeline with a logarithmic scale for dates, customize tick intervals, and render to PNG." + }, + { + "category": "timeline", + "file": "create-a-timeline-with-custom-date-format-ddmmmyyyy-and-export-the-chart-to-a-pdf-document.cs", + "title": "Create a timeline with custom date format (dd\u2011MMM\u2011yyyy) and export the chart to a PDF document." + }, + { + "category": "timeline", + "file": "draw-a-timeline-while-converting-the-entire-workbook-to-pdf-ensuring-the-timeline-appears-on-each-page.cs", + "title": "Draw a timeline while converting the entire workbook to PDF, ensuring the timeline appears on each page." + }, + { + "category": "timeline", + "file": "embed-a-rendered-timeline-image-into-a-pdf-report-header-aligning-it-with-the-document-title.cs", + "title": "Embed a rendered timeline image into a PDF report header, aligning it with the document title." + }, + { + "category": "timeline", + "file": "export-a-timeline-directly-to-a-memory-stream-in-pdf-format-for-further-processing-without-disk-io.cs", + "title": "Export a timeline directly to a memory stream in PDF format for further processing without disk I/O." + }, + { + "category": "timeline", + "file": "load-a-csv-file-containing-event-dates-convert-it-to-an-excel-worksheet-and-draw-a-timeline.cs", + "title": "Load a CSV file containing event dates, convert it to an Excel worksheet, and draw a timeline." + }, { "category": "timeline", "file": "load-an-excel-worksheet-insert-a-timeline-for-sales-data-and-export-the-sheet-to-pdf.cs", "title": "Load an Excel worksheet, insert a timeline for sales data, and export the sheet to PDF." }, + { + "category": "timeline", + "file": "render-a-timeline-with-a-3d-perspective-effect-adjust-depth-and-output-as-a-png-image.cs", + "title": "Render a timeline with a 3\u2011D perspective effect, adjust depth, and output as a PNG image." + }, + { + "category": "timeline", + "file": "render-a-timeline-with-data-labels-showing-percentages-adjust-label-font-size-and-save-as-png.cs", + "title": "Render a timeline with data labels showing percentages, adjust label font size, and save as PNG." + }, + { + "category": "timeline", + "file": "render-a-timeline-with-shadow-effects-adjust-opacity-and-output-the-image-as-a-png-with-transparency.cs", + "title": "Render a timeline with shadow effects, adjust opacity, and output the image as a PNG with transparency." + }, + { + "category": "timeline", + "file": "update-an-existing-timeline-by-adding-a-new-data-series-and-rerender-it-to-a-pdf-with-annotations.cs", + "title": "Update an existing timeline by adding a new data series and re\u2011render it to a PDF with annotations." + }, + { + "category": "timeline", + "file": "validate-timeline-date-ranges-against-a-predefined-calendar-and-log-any-inconsistencies-to-a-text-file.cs", + "title": "Validate timeline date ranges against a predefined calendar and log any inconsistencies to a text file." + }, { "category": "workbook-merger", "file": "add-a-timestamp-worksheet-indicating-the-exact-date-and-time-of-the-merge-operation.cs", diff --git a/timeline/add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs b/timeline/add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs new file mode 100644 index 0000000000..bae47870b8 --- /dev/null +++ b/timeline/add-interactive-hyperlinks-to-timeline-markers-that-open-related-worksheets-when-the-pdf-is-viewed.cs @@ -0,0 +1,72 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; +using Aspose.Cells.Rendering; + +namespace AsposeCellsTimelineHyperlinkDemo +{ + class Program + { + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet1 = workbook.Worksheets[0]; + sheet1.Name = "Data"; + + // Populate sample data for a pivot table + sheet1.Cells["A1"].Value = "Date"; + sheet1.Cells["B1"].Value = "Category"; + sheet1.Cells["C1"].Value = "Sales"; + + sheet1.Cells["A2"].Value = new DateTime(2023, 1, 1); + sheet1.Cells["B2"].Value = "A"; + sheet1.Cells["C2"].Value = 100; + + sheet1.Cells["A3"].Value = new DateTime(2023, 2, 1); + sheet1.Cells["B3"].Value = "B"; + sheet1.Cells["C3"].Value = 150; + + sheet1.Cells["A4"].Value = new DateTime(2023, 3, 1); + sheet1.Cells["B4"].Value = "A"; + sheet1.Cells["C4"].Value = 200; + + // Create a pivot table based on the data + int pivotIdx = sheet1.PivotTables.Add("A1:C4", "E1", "SalesPivot"); + PivotTable pivot = sheet1.PivotTables[pivotIdx]; + + // Add the Date field to the Page (filter) area – required for a timeline + pivot.AddFieldToArea(PivotFieldType.Page, "Date"); + pivot.AddFieldToArea(PivotFieldType.Row, "Category"); + pivot.AddFieldToArea(PivotFieldType.Data, "Sales"); + + // Refresh and calculate the pivot table + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a timeline control linked to the Date field of the pivot table + int timelineIdx = sheet1.Timelines.Add(pivot, "A10", "Date"); + Timeline timeline = sheet1.Timelines[timelineIdx]; + + // Add a second worksheet that will be the hyperlink target + Worksheet sheet2 = workbook.Worksheets.Add("Details"); + sheet2.Cells["A1"].Value = "Details for selected period"; + + // Set a hyperlink on the timeline shape to open the target worksheet cell when PDF is viewed + timeline.Shape.Hyperlink.Address = "Details!A1"; + timeline.Shape.Hyperlink.TextToDisplay = "Go to Details"; + + // Save the workbook as PDF with the hyperlink active + PdfSaveOptions pdfOptions = new PdfSaveOptions(); + workbook.Save("TimelineWithHyperlink.pdf", pdfOptions); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/agents.md b/timeline/agents.md new file mode 100644 index 0000000000..8dcbfba72b --- /dev/null +++ b/timeline/agents.md @@ -0,0 +1,112 @@ +--- +category: timeline +framework: .NET +parent: ../agents.md +version: v2 +--- + +# Persona + +You are a C# developer specializing in timeline features using Aspose.Cells for .NET. + +Generate simple, correct, production-quality examples that demonstrate ONE timeline scenario at a time. + +--- + +# Scope + +- Standalone .cs examples +- One operation per example +- Fully runnable with dotnet run +- No external dependencies + +--- + +# Required Namespaces + +using System; +using Aspose.Cells; +using Aspose.Cells.Pivot; + +--- + +# Key APIs + +- Timeline +- TimelineCollection +- PivotTable +- Worksheet.Timelines + +--- + +# Common Pattern + +1. Create workbook +2. Create sample date-based data +3. Create PivotTable +4. Create Timeline +5. Save workbook +6. Print success message + +--- + +# Timeline Rules + +- Timelines require a PivotTable data source +- Include valid date fields +- Use realistic sample data +- One example = one timeline operation + +--- + +# Input Strategy + +- Do NOT rely on external XLSX files +- Create all data programmatically +- Keep examples self-contained + +--- + +# Output Rules + +- Always generate output.xlsx +- Ensure workbook is saved successfully +- Output files are written to the working directory + +--- + +# Common Tasks + +- Create timeline +- Access timelines +- Modify timeline properties +- Connect timeline to PivotTable + +--- + +# Common Mistakes + +❌ var workbook = new Workbook(); +✅ Workbook workbook = new Workbook(); + +❌ Use timeline without date fields +✅ Create valid date-based source data + +❌ Workbook workbook = new Workbook("input.xlsx"); +✅ Workbook workbook = new Workbook(); + +--- + +# Code Simplicity + +- Keep examples concise +- Avoid unnecessary abstractions + +--- + +# General Rules + +Refer to the root agents.md for: +- Boundaries +- Testing requirements +- Build and run instructions diff --git a/timeline/apply-a-dark-theme-to-a-timeline-change-axis-colors-and-render-the-result-to-a-pdf.cs b/timeline/apply-a-dark-theme-to-a-timeline-change-axis-colors-and-render-the-result-to-a-pdf.cs new file mode 100644 index 0000000000..9e0efba071 --- /dev/null +++ b/timeline/apply-a-dark-theme-to-a-timeline-change-axis-colors-and-render-the-result-to-a-pdf.cs @@ -0,0 +1,94 @@ +using System; +using System.Drawing; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Charts; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; +using Aspose.Cells.Rendering; + +namespace AsposeCellsTimelineDarkThemePdf +{ + public class Program + { + public static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // ------------------------------------------------- + // Populate sample data (Date, Category, Value) + // ------------------------------------------------- + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Category"); + cells["C1"].PutValue("Value"); + + DateTime start = new DateTime(2023, 1, 1); + for (int i = 0; i < 6; i++) + { + cells[$"A{2 + i}"].PutValue(start.AddDays(i * 7)); + cells[$"B{2 + i}"].PutValue(i % 2 == 0 ? "Alpha" : "Beta"); + cells[$"C{2 + i}"].PutValue(10 + i * 5); + } + + // ------------------------------------------------- + // Create a PivotTable based on the data + // ------------------------------------------------- + PivotTableCollection pivots = sheet.PivotTables; + int pivotIdx = pivots.Add("A1:C7", "E1", "PivotTable1"); + PivotTable pivot = pivots[pivotIdx]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Column, "Category"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium9; + pivot.RefreshData(); + pivot.CalculateData(); + + // ------------------------------------------------- + // Add a Timeline linked to the PivotTable (base field: Date) + // ------------------------------------------------- + int timelineIdx = sheet.Timelines.Add(pivot, 12, 0, "Date"); + Timeline timeline = sheet.Timelines[timelineIdx]; + timeline.Caption = "Sales Timeline"; + timeline.ShowHeader = true; + timeline.ShowHorizontalScrollbar = true; + timeline.ShowSelectionLabel = true; + timeline.ShowTimeLevel = true; + + // ------------------------------------------------- + // Apply a dark custom theme (background dark, text light) + // ------------------------------------------------- + Color[] darkTheme = new Color[] + { + Color.FromArgb(30, 30, 30), // Background1 (dark gray) + Color.White, // Text1 (white) + Color.FromArgb(45, 45, 45), // Background2 (slightly lighter gray) + Color.White, // Text2 (white) + Color.FromArgb(0, 120, 215), // Accent1 (blue) + Color.FromArgb(0, 153, 0), // Accent2 (green) + Color.FromArgb(255, 140, 0), // Accent3 (orange) + Color.FromArgb(191, 0, 0), // Accent4 (red) + Color.FromArgb(102, 102, 102) // Accent5 (medium gray) + }; + // Note: Aspose.Cells does not provide a direct API to replace the built‑in theme, + // but you can apply the colors to styles as needed. For this sample we keep it simple. + + // ------------------------------------------------- + // Save the workbook as PDF + // ------------------------------------------------- + string outputPath = "TimelineDarkTheme.pdf"; + workbook.Save(outputPath, SaveFormat.Pdf); + Console.WriteLine($"Workbook saved to {Path.GetFullPath(outputPath)}"); + } + catch (Exception ex) + { + // Runtime safety: log any unexpected errors + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/apply-a-gradient-background-to-a-timeline-adjust-label-rotation-and-render-it-to-a-bmp-image.cs b/timeline/apply-a-gradient-background-to-a-timeline-adjust-label-rotation-and-render-it-to-a-bmp-image.cs new file mode 100644 index 0000000000..097dbbe80a --- /dev/null +++ b/timeline/apply-a-gradient-background-to-a-timeline-adjust-label-rotation-and-render-it-to-a-bmp-image.cs @@ -0,0 +1,73 @@ +using System; +using System.Drawing; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Drawing; +using Aspose.Cells.Rendering; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class TimelineGradientExample +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate worksheet with sample data (Date and Value) + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Value"); + cells["A2"].PutValue(new DateTime(2023, 1, 1)); + cells["B2"].PutValue(100); + cells["A3"].PutValue(new DateTime(2023, 2, 1)); + cells["B3"].PutValue(200); + cells["A4"].PutValue(new DateTime(2023, 3, 1)); + cells["B4"].PutValue(300); + + // Add a PivotTable based on the data + int pivotIndex = sheet.PivotTables.Add("A1:B4", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a Timeline linked to the PivotTable (placed at row 6, column 0) + // Use the actual field name from the pivot to avoid mismatches + string dateFieldName = pivot.RowFields[0].Name; + sheet.Timelines.Add(pivot, 5, 0, dateFieldName); + Timeline timeline = sheet.Timelines[0]; + + // Apply a two‑color gradient background to the Timeline shape + timeline.Shape.Fill.FillType = FillType.Gradient; + GradientFill gradientFill = timeline.Shape.Fill.GradientFill; + gradientFill.SetTwoColorGradient( + Color.LightBlue, // First gradient color + Color.DarkBlue, // Second gradient color + GradientStyleType.Horizontal, + 1); // Variant + + // Rotate the Timeline shape (affects the label orientation) + timeline.Shape.RotationAngle = 45; // degrees + + // Render the worksheet (which contains the Timeline) to a BMP image + ImageOrPrintOptions imgOptions = new ImageOrPrintOptions + { + ImageType = ImageType.Bmp + }; + SheetRender sheetRender = new SheetRender(sheet, imgOptions); + sheetRender.ToImage(0, "TimelineOutput.bmp"); + + // Optionally save the workbook for verification + workbook.Save("TimelineWithGradient.xlsx"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/apply-a-watermark-text-over-a-rendered-timeline-image-and-export-the-final-picture-as-a-pdf.cs b/timeline/apply-a-watermark-text-over-a-rendered-timeline-image-and-export-the-final-picture-as-a-pdf.cs new file mode 100644 index 0000000000..d139703387 --- /dev/null +++ b/timeline/apply-a-watermark-text-over-a-rendered-timeline-image-and-export-the-final-picture-as-a-pdf.cs @@ -0,0 +1,59 @@ +using System; +using System.Drawing; +using Aspose.Cells; +using Aspose.Cells.Rendering; +using Aspose.Cells.Charts; + +class TimelineWatermarkPdf +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Populate sample data representing a timeline (date vs. value) + sheet.Cells["A1"].PutValue("Date"); + sheet.Cells["B1"].PutValue("Value"); + sheet.Cells["A2"].PutValue(new DateTime(2023, 1, 1)); + sheet.Cells["B2"].PutValue(10); + sheet.Cells["A3"].PutValue(new DateTime(2023, 2, 1)); + sheet.Cells["B3"].PutValue(20); + sheet.Cells["A4"].PutValue(new DateTime(2023, 3, 1)); + sheet.Cells["B4"].PutValue(15); + + // Add a line chart that will act as the timeline visual + int chartIndex = sheet.Charts.Add(ChartType.Line, 5, 0, 20, 15); + Chart chart = sheet.Charts[chartIndex]; + chart.NSeries.Add("B2:B4", true); // Values + chart.NSeries.CategoryData = "A2:A4"; // Dates + chart.Title.Text = "Project Timeline"; + + // Create a rendering font for the watermark text + RenderingFont watermarkFont = new RenderingFont("Arial", 48) + { + Color = Color.Red, + Bold = true, + Italic = true + }; + + // Instantiate a text watermark and configure its appearance + RenderingWatermark watermark = new RenderingWatermark("CONFIDENTIAL", watermarkFont) + { + HAlignment = TextAlignmentType.Center, + VAlignment = TextAlignmentType.Center, + Rotation = 45f, // Rotate 45 degrees + Opacity = 0.3f, // Semi‑transparent + IsBackground = true // Place behind page contents + }; + + // Set PDF save options to include the watermark + PdfSaveOptions pdfOptions = new PdfSaveOptions + { + Watermark = watermark + }; + + // Save the workbook as a PDF; the chart (timeline) will be rendered with the watermark + workbook.Save("TimelineWithWatermark.pdf", pdfOptions); + } +} \ No newline at end of file diff --git a/timeline/apply-conditional-formatting-to-timeline-bars-based-on-performance-thresholds-and-export-the-result-as-a-pdf.cs b/timeline/apply-conditional-formatting-to-timeline-bars-based-on-performance-thresholds-and-export-the-result-as-a-pdf.cs new file mode 100644 index 0000000000..14481a61d6 --- /dev/null +++ b/timeline/apply-conditional-formatting-to-timeline-bars-based-on-performance-thresholds-and-export-the-result-as-a-pdf.cs @@ -0,0 +1,92 @@ +using System; +using System.Drawing; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class TimelineConditionalFormattingPdf +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate sample data: Date and Performance values + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Performance"); + DateTime start = new DateTime(2023, 1, 1); + for (int i = 0; i < 12; i++) + { + cells[i + 1, 0].PutValue(start.AddMonths(i)); + cells[i + 1, 1].PutValue(30 + i * 6); + } + + // Create a pivot table that will serve as the data source for the timeline + int pivotIdx = sheet.PivotTables.Add("A1:B13", "D1", "PerfPivot"); + PivotTable pivot = sheet.PivotTables[pivotIdx]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Performance"); + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a timeline linked to the pivot table (based on the Date field) + try + { + TimelineCollection timelines = sheet.Timelines; + int timelineIdx = timelines.Add(pivot, "F1", "Date"); + Timeline timeline = timelines[timelineIdx]; + timeline.Shape.Width = 500; + timeline.Shape.Height = 80; + timeline.Caption = "Performance Timeline"; + } + catch (Exception ex) + { + // Timeline creation can fail if the pivot configuration is not suitable. + Console.WriteLine($"Timeline could not be added: {ex.Message}"); + } + + // Apply conditional formatting to the Performance column (B2:B13) + int cfIdx = sheet.ConditionalFormattings.Add(); + FormatConditionCollection fcs = sheet.ConditionalFormattings[cfIdx]; + + // Define the range for conditional formatting + CellArea perfArea = new CellArea + { + StartRow = 1, + EndRow = 12, + StartColumn = 1, + EndColumn = 1 + }; + fcs.AddArea(perfArea); + + // Rule 1: Performance > 80 -> Green background + int ruleIdx = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.GreaterThan, "80", null); + FormatCondition rule = fcs[ruleIdx]; + rule.Style.BackgroundColor = Color.LightGreen; + + // Rule 2: 50 <= Performance <= 80 -> Yellow background + ruleIdx = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.Between, "50", "80"); + rule = fcs[ruleIdx]; + rule.Style.BackgroundColor = Color.LightYellow; + + // Rule 3: Performance < 50 -> Red background + ruleIdx = fcs.AddCondition(FormatConditionType.CellValue, OperatorType.LessThan, "50", null); + rule = fcs[ruleIdx]; + rule.Style.BackgroundColor = Color.LightCoral; + + // Save the workbook as PDF (includes the timeline and conditional formatting) + string outputPath = "PerformanceTimeline.pdf"; + workbook.Save(outputPath, SaveFormat.Pdf); + Console.WriteLine($"Workbook saved to {Path.GetFullPath(outputPath)}"); + } + catch (Exception e) + { + Console.WriteLine($"An error occurred: {e.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/batch-convert-excel-files-add-a-timeline-to-each-and-save-pdfs-to-an-output-directory.cs b/timeline/batch-convert-excel-files-add-a-timeline-to-each-and-save-pdfs-to-an-output-directory.cs new file mode 100644 index 0000000000..2e8be97652 --- /dev/null +++ b/timeline/batch-convert-excel-files-add-a-timeline-to-each-and-save-pdfs-to-an-output-directory.cs @@ -0,0 +1,89 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; +using Aspose.Cells.Utility; + +class BatchConvertWithTimeline +{ + static void Main() + { + // Input folder containing Excel files + string inputFolder = @"C:\InputExcel"; + // Output folder where PDFs will be saved + string outputFolder = @"C:\OutputPdf"; + + try + { + // Verify input folder exists + if (!Directory.Exists(inputFolder)) + { + Console.WriteLine($"Input folder not found: {inputFolder}"); + return; + } + + // Ensure the output directory exists + Directory.CreateDirectory(outputFolder); + + // Process each .xlsx file in the input folder + foreach (string excelPath in Directory.GetFiles(inputFolder, "*.xlsx")) + { + // Verify the file still exists before loading + if (!File.Exists(excelPath)) + { + Console.WriteLine($"File not found (skipped): {excelPath}"); + continue; + } + + try + { + // Load the workbook + Workbook workbook = new Workbook(excelPath); + Worksheet sheet = workbook.Worksheets[0]; + + // ------------------------------------------------------------ + // Create a simple PivotTable as a data source for the Timeline. + // This example assumes that the source data occupies A1:B10. + // Adjust the range as needed for real data. + // ------------------------------------------------------------ + int pivotIndex = sheet.PivotTables.Add("A1:B10", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + + // Add the first column (index 0) as a Row field – typically a date field. + pivot.AddFieldToArea(PivotFieldType.Row, 0); + + // ------------------------------------------------------------ + // Add a Timeline control linked to the PivotTable. + // The Timeline will be placed with its upper‑left corner at cell E1 + // and will use the field named "Date" from the PivotTable. + // ------------------------------------------------------------ + sheet.Timelines.Add(pivot, "E1", "Date"); + + // Save the modified workbook to a temporary file (required before conversion). + string tempExcelPath = Path.Combine(outputFolder, + Path.GetFileNameWithoutExtension(excelPath) + "_temp.xlsx"); + workbook.Save(tempExcelPath); + + // Convert the temporary Excel file to PDF using the provided utility. + string pdfPath = Path.Combine(outputFolder, + Path.GetFileNameWithoutExtension(excelPath) + ".pdf"); + ConversionUtility.Convert(tempExcelPath, pdfPath); + + // Optional: delete the temporary Excel file. + File.Delete(tempExcelPath); + + Console.WriteLine($"Converted '{excelPath}' to PDF with Timeline: '{pdfPath}'"); + } + catch (Exception ex) + { + Console.WriteLine($"Error processing file '{excelPath}': {ex.Message}"); + } + } + } + catch (Exception ex) + { + Console.WriteLine($"Unexpected error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/batch-process-multiple-worksheets-creating-individual-timelines-for-each-and-saving-them-as-separate-png-files.cs b/timeline/batch-process-multiple-worksheets-creating-individual-timelines-for-each-and-saving-them-as-separate-png-files.cs new file mode 100644 index 0000000000..7526723faa --- /dev/null +++ b/timeline/batch-process-multiple-worksheets-creating-individual-timelines-for-each-and-saving-them-as-separate-png-files.cs @@ -0,0 +1,83 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Rendering; + +namespace AsposeCellsBatchTimeline +{ + public class Program + { + public static void Main() + { + try + { + // Create a new workbook + Workbook workbook = new Workbook(); + + // Number of worksheets to process + int sheetCount = 3; + + // Prepare sample data for each worksheet and add a timeline + for (int i = 0; i < sheetCount; i++) + { + // Add a new worksheet (first one already exists) + Worksheet sheet = i == 0 ? workbook.Worksheets[0] : workbook.Worksheets.Add($"Sheet{i + 1}"); + + // Populate sample data: Date column and Sales column + sheet.Cells["A1"].PutValue("Date"); + sheet.Cells["B1"].PutValue("Sales"); + for (int row = 2; row <= 6; row++) + { + sheet.Cells[$"A{row}"].PutValue(new DateTime(2023, 1, row - 1)); + sheet.Cells[$"B{row}"].PutValue(100 * row); + } + + // Create a pivot table using the sample data + int pivotIndex = sheet.PivotTables.Add("A1:B6", "D3", $"Pivot{i + 1}"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + + // Add the Date field to the Page area (required for Timeline) + pivot.AddFieldToArea(PivotFieldType.Page, "Date"); + // Add the Sales field to the Data area + pivot.AddFieldToArea(PivotFieldType.Data, "Sales"); + + // Refresh and calculate the pivot table + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a timeline linked to the pivot table + sheet.Timelines.Add(pivot, "F1", "Date"); + } + + // Render each worksheet (with its timeline) to a separate PNG file + for (int i = 0; i < workbook.Worksheets.Count; i++) + { + Worksheet sheet = workbook.Worksheets[i]; + + // Configure image rendering options + ImageOrPrintOptions imgOptions = new ImageOrPrintOptions + { + ImageType = Aspose.Cells.Drawing.ImageType.Png, + OnePagePerSheet = true + }; + + // Create a SheetRender for the current worksheet + SheetRender renderer = new SheetRender(sheet, imgOptions); + + // Render the first page of the sheet to a PNG file + string outputPath = Path.Combine(Environment.CurrentDirectory, $"{sheet.Name}_Timeline.png"); + renderer.ToImage(0, outputPath); + } + + // Optional: Save the workbook for reference + string workbookPath = Path.Combine(Environment.CurrentDirectory, "BatchTimelineWorkbook.xlsx"); + workbook.Save(workbookPath); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/combine-two-separate-timelines-into-a-single-composite-view-and-save-the-merged-chart-as-an-svg-file.cs b/timeline/combine-two-separate-timelines-into-a-single-composite-view-and-save-the-merged-chart-as-an-svg-file.cs new file mode 100644 index 0000000000..52f49884d5 --- /dev/null +++ b/timeline/combine-two-separate-timelines-into-a-single-composite-view-and-save-the-merged-chart-as-an-svg-file.cs @@ -0,0 +1,87 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; +using Aspose.Cells.Rendering; + +namespace TimelineMergeToSvg +{ + class Program + { + static void Main() + { + try + { + // ---------- Create first workbook with a timeline ---------- + Workbook wb1 = new Workbook(); + Worksheet ws1 = wb1.Worksheets[0]; + + // Sample data + ws1.Cells["A1"].Value = "Date"; + ws1.Cells["B1"].Value = "Sales"; + ws1.Cells["A2"].Value = new DateTime(2023, 1, 1); + ws1.Cells["B2"].Value = 1200; + ws1.Cells["A3"].Value = new DateTime(2023, 2, 1); + ws1.Cells["B3"].Value = 1500; + ws1.Cells["A4"].Value = new DateTime(2023, 3, 1); + ws1.Cells["B4"].Value = 1800; + + // Pivot table for timeline source + int ptIdx1 = ws1.PivotTables.Add("A1:B4", "D1", "Pivot1"); + PivotTable pt1 = ws1.PivotTables[ptIdx1]; + pt1.AddFieldToArea(PivotFieldType.Row, "Date"); + pt1.AddFieldToArea(PivotFieldType.Data, "Sales"); + pt1.RefreshData(); + pt1.CalculateData(); + + // Add timeline linked to the pivot table (place it below the data to avoid overlap) + ws1.Timelines.Add(pt1, 5, 0, "Date"); + + // ---------- Create second workbook with a timeline ---------- + Workbook wb2 = new Workbook(); + Worksheet ws2 = wb2.Worksheets[0]; + + // Sample data + ws2.Cells["A1"].Value = "Date"; + ws2.Cells["B1"].Value = "Revenue"; + ws2.Cells["A2"].Value = new DateTime(2023, 1, 15); + ws2.Cells["B2"].Value = 800; + ws2.Cells["A3"].Value = new DateTime(2023, 2, 15); + ws2.Cells["B3"].Value = 950; + ws2.Cells["A4"].Value = new DateTime(2023, 3, 15); + ws2.Cells["B4"].Value = 1100; + + // Pivot table for timeline source + int ptIdx2 = ws2.PivotTables.Add("A1:B4", "D1", "Pivot2"); + PivotTable pt2 = ws2.PivotTables[ptIdx2]; + pt2.AddFieldToArea(PivotFieldType.Row, "Date"); + pt2.AddFieldToArea(PivotFieldType.Data, "Revenue"); + pt2.RefreshData(); + pt2.CalculateData(); + + // Add timeline linked to the second pivot table (place it below the data) + ws2.Timelines.Add(pt2, 5, 0, "Date"); + + // ---------- Combine the two workbooks ---------- + // The destination workbook (wb1) will receive the content of wb2 + wb1.Combine(wb2); + + // ---------- Render the combined worksheet to SVG ---------- + SvgImageOptions svgOptions = new SvgImageOptions + { + FitToViewPort = true // make SVG fit the viewport + }; + + // Render the first worksheet (index 0) to SVG + SheetRender renderer = new SheetRender(wb1.Worksheets[0], svgOptions); + renderer.ToImage(0, "CombinedTimelines.svg"); + + Console.WriteLine("Combined timelines rendered to SVG successfully."); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/create-a-timeline-using-a-custom-template-file-then-replace-placeholder-text-with-dynamic-project-names.cs b/timeline/create-a-timeline-using-a-custom-template-file-then-replace-placeholder-text-with-dynamic-project-names.cs new file mode 100644 index 0000000000..5edced5393 --- /dev/null +++ b/timeline/create-a-timeline-using-a-custom-template-file-then-replace-placeholder-text-with-dynamic-project-names.cs @@ -0,0 +1,75 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; + +class Program +{ + static void Main() + { + try + { + const string templatePath = "ProjectTemplate.xlsx"; + const string outputPath = "ProjectTimeline.xlsx"; + + // Load template if it exists; otherwise create a new workbook + Workbook workbook = File.Exists(templatePath) ? new Workbook(templatePath) : new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // ------------------------------------------------- + // Prepare data required for the Timeline (date field) + // ------------------------------------------------- + sheet.Cells["A1"].PutValue("Date"); + sheet.Cells["A2"].PutValue(DateTime.Now.AddDays(-3)); + sheet.Cells["A3"].PutValue(DateTime.Now.AddDays(-2)); + sheet.Cells["A4"].PutValue(DateTime.Now.AddDays(-1)); + sheet.Cells["A5"].PutValue(DateTime.Now); + + // Optional numeric field for the PivotTable + sheet.Cells["B1"].PutValue("Value"); + sheet.Cells["B2"].PutValue(10); + sheet.Cells["B3"].PutValue(20); + sheet.Cells["B4"].PutValue(30); + sheet.Cells["B5"].PutValue(40); + + // ------------------------------------------------- + // Create a PivotTable that will serve as the Timeline data source + // ------------------------------------------------- + int pivotIdx = sheet.PivotTables.Add("A1:B5", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIdx]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.RefreshData(); + pivot.CalculateData(); + + // ------------------------------------------------- + // Add the Timeline linked to the PivotTable + // ------------------------------------------------- + // The Timeline will start at cell F1 (upper‑left corner of its range) + sheet.Timelines.Add(pivot, "F1", "Date"); + + // ------------------------------------------------- + // Replace placeholder text with dynamic project names + // ------------------------------------------------- + string projectName = "Apollo"; // This could come from any data source + + foreach (Cell cell in sheet.Cells) + { + if (cell.Type == CellValueType.IsString && cell.StringValue.Contains("{{ProjectName}}")) + { + string updated = cell.StringValue.Replace("{{ProjectName}}", projectName); + cell.PutValue(updated); + } + } + + // ------------------------------------------------- + // Save the resulting workbook + // ------------------------------------------------- + workbook.Save(outputPath); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/create-a-timeline-with-a-logarithmic-scale-for-dates-customize-tick-intervals-and-render-to-png.cs b/timeline/create-a-timeline-with-a-logarithmic-scale-for-dates-customize-tick-intervals-and-render-to-png.cs new file mode 100644 index 0000000000..ddba6bf431 --- /dev/null +++ b/timeline/create-a-timeline-with-a-logarithmic-scale-for-dates-customize-tick-intervals-and-render-to-png.cs @@ -0,0 +1,48 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Charts; +using Aspose.Cells.Rendering; + +namespace AsposeCellsTimelineLogChart +{ + class Program + { + static void Main() + { + try + { + // Create a new workbook (or load a template if it exists) + string templatePath = "Template.xlsx"; + Workbook workbook = File.Exists(templatePath) ? new Workbook(templatePath) : new Workbook(); + + // Get the first worksheet + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate sample data: dates in column A and numeric values in column B + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Value"); + DateTime start = new DateTime(2023, 1, 1); + for (int i = 0; i < 10; i++) + { + // Exponential dates to illustrate logarithmic scaling + cells[i + 2, 0].PutValue(start.AddDays(Math.Pow(2, i))); + // Sample numeric value + cells[i + 2, 1].PutValue(i + 1); + } + + // Save the workbook + string outputPath = "TimelineLogChart.xlsx"; + workbook.Save(outputPath); + Console.WriteLine($"Workbook saved to {Path.GetFullPath(outputPath)}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/create-a-timeline-with-custom-date-format-ddmmmyyyy-and-export-the-chart-to-a-pdf-document.cs b/timeline/create-a-timeline-with-custom-date-format-ddmmmyyyy-and-export-the-chart-to-a-pdf-document.cs new file mode 100644 index 0000000000..bb04b1ef41 --- /dev/null +++ b/timeline/create-a-timeline-with-custom-date-format-ddmmmyyyy-and-export-the-chart-to-a-pdf-document.cs @@ -0,0 +1,78 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Charts; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class Program +{ + static void Main() + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate sample data: Fruit, Date, Amount + cells["A1"].PutValue("Fruit"); + cells["B1"].PutValue("Date"); + cells["C1"].PutValue("Amount"); + + string[] fruits = { "Apple", "Banana", "Cherry", "Date" }; + DateTime[] dates = { + new DateTime(2021, 1, 5), + new DateTime(2021, 2, 10), + new DateTime(2021, 3, 15), + new DateTime(2021, 4, 20) + }; + int[] amounts = { 100, 150, 200, 250 }; + + for (int i = 0; i < fruits.Length; i++) + { + cells[i + 1, 0].PutValue(fruits[i]); // Fruit column + cells[i + 1, 1].PutValue(dates[i]); // Date column + cells[i + 1, 2].PutValue(amounts[i]); // Amount column + } + + // Create a date style with custom format dd-MMM-yyyy + Style dateStyle = workbook.CreateStyle(); + dateStyle.Custom = "dd-MMM-yyyy"; + + // Apply the custom date style to the date cells + for (int i = 1; i <= fruits.Length; i++) + { + cells[i, 1].SetStyle(dateStyle); + } + + // Add a PivotTable based on the data range + PivotTableCollection pivots = sheet.PivotTables; + int pivotIndex = pivots.Add("A1:C5", "E1", "PivotTable1"); + PivotTable pivot = pivots[pivotIndex]; + pivot.AddFieldToArea(PivotFieldType.Row, "Fruit"); + pivot.AddFieldToArea(PivotFieldType.Column, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Amount"); + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a Timeline linked to the PivotTable using the Date field + TimelineCollection timelines = sheet.Timelines; + int timelineIndex = timelines.Add(pivot, "G1", "Date"); + Timeline timeline = timelines[timelineIndex]; + timeline.Caption = "Sales Timeline"; + + // Add a line chart that uses the same data + int chartIndex = sheet.Charts.Add(ChartType.Line, 15, 0, 30, 15); + Chart chart = sheet.Charts[chartIndex]; + chart.NSeries.Add("C2:C5", true); // Values + chart.NSeries.CategoryData = "B2:B5"; // Dates as categories + + // Set the X‑axis values format to match the custom date format + chart.NSeries[0].XValuesFormatCode = "dd-MMM-yyyy"; + + // Export the chart to a PDF file + chart.ToPdf("TimelineChart.pdf"); + + // Save the workbook (optional, for verification) + workbook.Save("TimelineDemo.xlsx"); + } +} \ No newline at end of file diff --git a/timeline/draw-a-timeline-while-converting-the-entire-workbook-to-pdf-ensuring-the-timeline-appears-on-each-page.cs b/timeline/draw-a-timeline-while-converting-the-entire-workbook-to-pdf-ensuring-the-timeline-appears-on-each-page.cs new file mode 100644 index 0000000000..afed13b6e0 --- /dev/null +++ b/timeline/draw-a-timeline-while-converting-the-entire-workbook-to-pdf-ensuring-the-timeline-appears-on-each-page.cs @@ -0,0 +1,54 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class TimelinePdfDemo +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Populate worksheet with sample date and numeric data + sheet.Cells["A1"].Value = "Date"; + sheet.Cells["B1"].Value = "Value"; + sheet.Cells["A2"].Value = new DateTime(2023, 1, 1); + sheet.Cells["B2"].Value = 100; + sheet.Cells["A3"].Value = new DateTime(2023, 2, 1); + sheet.Cells["B3"].Value = 200; + sheet.Cells["A4"].Value = new DateTime(2023, 3, 1); + sheet.Cells["B4"].Value = 300; + + // Create a pivot table that will serve as the data source for the timeline + int pivotIndex = sheet.PivotTables.Add("A1:B4", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a timeline linked to the pivot table + int timelineIndex = sheet.Timelines.Add(pivot, 0, 0, "Date"); + Timeline timeline = sheet.Timelines[timelineIndex]; + timeline.Caption = "Sales Timeline"; + + // Configure PDF save options so the whole sheet (including the timeline) fits on a single page + PdfSaveOptions pdfOptions = new PdfSaveOptions + { + OnePagePerSheet = true, + AllColumnsInOnePagePerSheet = true + }; + + // Save the workbook as a PDF file + workbook.Save("TimelineWorkbook.pdf", pdfOptions); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/embed-a-rendered-timeline-image-into-a-pdf-report-header-aligning-it-with-the-document-title.cs b/timeline/embed-a-rendered-timeline-image-into-a-pdf-report-header-aligning-it-with-the-document-title.cs new file mode 100644 index 0000000000..cfeea36cee --- /dev/null +++ b/timeline/embed-a-rendered-timeline-image-into-a-pdf-report-header-aligning-it-with-the-document-title.cs @@ -0,0 +1,81 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Charts; +using Aspose.Cells.Pivot; +using Aspose.Cells.Rendering; +using Aspose.Cells.Drawing; + +namespace AsposeCellsTimelinePdfHeader +{ + class Program + { + static void Main() + { + try + { + // 1. Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // 2. Populate sample data (date and value) for the pivot table + sheet.Cells["A1"].PutValue("Date"); + sheet.Cells["B1"].PutValue("Value"); + sheet.Cells["A2"].PutValue(new DateTime(2023, 1, 1)); + sheet.Cells["B2"].PutValue(120); + sheet.Cells["A3"].PutValue(new DateTime(2023, 2, 1)); + sheet.Cells["B3"].PutValue(150); + sheet.Cells["A4"].PutValue(new DateTime(2023, 3, 1)); + sheet.Cells["B4"].PutValue(180); + + // 3. Create a pivot table based on the data + int pivotIdx = sheet.PivotTables.Add("A1:B4", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIdx]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.RefreshData(); + pivot.CalculateData(); + + // 4. Add a Timeline control linked to the pivot table (using the "Date" field) + int timelineIdx = sheet.Timelines.Add(pivot, 0, 0, "Date"); + // Optional: adjust size/position if needed (requires Timeline type support) + // sheet.Timelines[timelineIdx].WidthPixel = 400; + // sheet.Timelines[timelineIdx].HeightPixel = 80; + + // 5. Render the worksheet (which now contains the timeline) to an image in memory + ImageOrPrintOptions imgOptions = new ImageOrPrintOptions + { + ImageType = ImageType.Png, + OnePagePerSheet = true + }; + SheetRender renderer = new SheetRender(sheet, imgOptions); + using (MemoryStream imgStream = new MemoryStream()) + { + // Render first (and only) page to the stream + renderer.ToImage(0, imgStream); + byte[] imgBytes = imgStream.ToArray(); + + // 6. Set the rendered timeline image as a header picture (center section) + // Section index: 1 = center + sheet.PageSetup.SetHeaderPicture(1, imgBytes); + + // 7. Build the header script: title text followed by the image placeholder (&G) + sheet.PageSetup.SetHeader(1, "Report Title &G"); + } + + // 8. Save the workbook as PDF, ensuring header/footer is included + PdfSaveOptions pdfOptions = new PdfSaveOptions + { + DisplayDocTitle = true + }; + string outputPath = "TimelineReport.pdf"; + workbook.Save(outputPath, pdfOptions); + Console.WriteLine($"PDF saved successfully to '{Path.GetFullPath(outputPath)}'."); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/export-a-timeline-directly-to-a-memory-stream-in-pdf-format-for-further-processing-without-disk-io.cs b/timeline/export-a-timeline-directly-to-a-memory-stream-in-pdf-format-for-further-processing-without-disk-io.cs new file mode 100644 index 0000000000..5663ab2e9b --- /dev/null +++ b/timeline/export-a-timeline-directly-to-a-memory-stream-in-pdf-format-for-further-processing-without-disk-io.cs @@ -0,0 +1,56 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class ExportTimelinePdfToMemoryStream +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // Populate worksheet with sample date and value data + sheet.Cells["A1"].Value = "Date"; + sheet.Cells["B1"].Value = "Value"; + + sheet.Cells["A2"].Value = new DateTime(2023, 1, 1); + sheet.Cells["B2"].Value = 100; + + sheet.Cells["A3"].Value = new DateTime(2023, 2, 1); + sheet.Cells["B3"].Value = 150; + + sheet.Cells["A4"].Value = new DateTime(2023, 3, 1); + sheet.Cells["B4"].Value = 200; + + // Add a pivot table that will serve as the data source for the timeline + int pivotIndex = sheet.PivotTables.Add("A1:B4", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a timeline linked to the pivot table's date field + // Place the timeline starting at cell G1 (row 0, column 6) to avoid overlap + sheet.Timelines.Add(pivot, 0, 6, "Date"); + + // Export the workbook (which now contains the timeline) to a PDF in a memory stream + using (MemoryStream pdfStream = new MemoryStream()) + { + workbook.Save(pdfStream, SaveFormat.Pdf); + pdfStream.Position = 0; + Console.WriteLine($"PDF stream length: {pdfStream.Length} bytes"); + // The pdfStream can now be used for further processing without any disk I/O + } + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/load-a-csv-file-containing-event-dates-convert-it-to-an-excel-worksheet-and-draw-a-timeline.cs b/timeline/load-a-csv-file-containing-event-dates-convert-it-to-an-excel-worksheet-and-draw-a-timeline.cs new file mode 100644 index 0000000000..75e183e1e3 --- /dev/null +++ b/timeline/load-a-csv-file-containing-event-dates-convert-it-to-an-excel-worksheet-and-draw-a-timeline.cs @@ -0,0 +1,72 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class TimelineFromCsv +{ + static void Main() + { + try + { + // 1. Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // 2. Import the CSV file into the worksheet + string csvPath = "events.csv"; // CSV file containing Event and Date columns + string delimiter = ","; // CSV delimiter + bool convertNumeric = true; // Convert numeric strings to numbers + int startRow = 0; // Start importing at cell A1 (row index 0) + int startColumn = 0; // Start importing at column A (column index 0) + + // Prevent FileNotFoundException + if (!File.Exists(csvPath)) + { + Console.WriteLine($"CSV file not found: {Path.GetFullPath(csvPath)}"); + return; + } + + cells.ImportCSV(csvPath, delimiter, convertNumeric, startRow, startColumn); + + // 3. Create a PivotTable that will serve as the data source for the Timeline + // Assuming the CSV has two columns: "Event" (A) and "Date" (B) + // Use a range that covers the imported data (e.g., A1:B100) + int pivotIndex = sheet.PivotTables.Add("A1:B100", "D1", "EventPivot"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + + // Add the Date field as the row axis (required for a Timeline) + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + + // Add the Event field as a data field (count of events per date) + pivot.AddFieldToArea(PivotFieldType.Data, "Event"); + + // Refresh the PivotTable to populate it with data + pivot.RefreshData(); + pivot.CalculateData(); + + // 4. Add a Timeline control linked to the PivotTable's Date field + // Place the Timeline starting at cell G5 + int timelineIndex = sheet.Timelines.Add(pivot, "G5", "Date"); + Timeline timeline = sheet.Timelines[timelineIndex]; + + // Optional: customize the Timeline appearance via its Shape property + timeline.Shape.Top = 200; // vertical offset in pixels + timeline.Shape.Left = 50; // horizontal offset in pixels + timeline.Shape.Width = 600; // width in pixels + timeline.Shape.Height = 80; // height in pixels + timeline.Caption = "Event Timeline"; + + // 5. Save the workbook with the Timeline embedded + string outputPath = "TimelineFromCsv.xlsx"; + workbook.Save(outputPath); + Console.WriteLine($"Workbook saved successfully: {Path.GetFullPath(outputPath)}"); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + } + } +} \ No newline at end of file diff --git a/timeline/load-an-excel-worksheet-insert-a-timeline-for-sales-data-and-export-the-sheet-to-pdf.cs b/timeline/load-an-excel-worksheet-insert-a-timeline-for-sales-data-and-export-the-sheet-to-pdf.cs new file mode 100644 index 0000000000..f75c2cd8cb --- /dev/null +++ b/timeline/load-an-excel-worksheet-insert-a-timeline-for-sales-data-and-export-the-sheet-to-pdf.cs @@ -0,0 +1,71 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Utility; + +namespace AsposeCellsTimelineToPdf +{ + class Program + { + static void Main() + { + try + { + // 1. Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // 2. Populate worksheet with sample sales data (Date and Sales) + sheet.Cells["A1"].PutValue("Date"); + sheet.Cells["B1"].PutValue("Sales"); + sheet.Cells["A2"].PutValue(new DateTime(2023, 1, 1)); + sheet.Cells["B2"].PutValue(1500); + sheet.Cells["A3"].PutValue(new DateTime(2023, 2, 1)); + sheet.Cells["B3"].PutValue(2300); + sheet.Cells["A4"].PutValue(new DateTime(2023, 3, 1)); + sheet.Cells["B4"].PutValue(1800); + sheet.Cells["A5"].PutValue(new DateTime(2023, 4, 1)); + sheet.Cells["B5"].PutValue(2100); + + // 3. Add a pivot table based on the sales data (placed at D2) + int pivotIndex = sheet.PivotTables.Add("A1:B5", "D2", "SalesPivot"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Sales"); + pivot.RefreshData(); + pivot.CalculateData(); + + // 4. Insert a Timeline control linked to the pivot table (starting at G2) + try + { + sheet.Timelines.Add(pivot, 1, 6, "Date"); + } + catch (Exception ex) + { + Console.WriteLine($"Timeline could not be added: {ex.Message}"); + } + + // 5. Save the workbook to a temporary Excel file + string excelPath = "SalesTimeline.xlsx"; + workbook.Save(excelPath); + + // 6. Convert the saved Excel file to PDF using ConversionUtility + string pdfPath = "SalesTimeline.pdf"; + if (File.Exists(excelPath)) + { + ConversionUtility.Convert(excelPath, pdfPath); + Console.WriteLine($"Workbook saved to '{excelPath}' and converted to PDF at '{pdfPath}'."); + } + else + { + Console.WriteLine($"Excel file '{excelPath}' not found. Conversion skipped."); + } + } + catch (Exception e) + { + Console.WriteLine($"An error occurred: {e.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/render-a-timeline-with-a-3d-perspective-effect-adjust-depth-and-output-as-a-png-image.cs b/timeline/render-a-timeline-with-a-3d-perspective-effect-adjust-depth-and-output-as-a-png-image.cs new file mode 100644 index 0000000000..10fb6799f7 --- /dev/null +++ b/timeline/render-a-timeline-with-a-3d-perspective-effect-adjust-depth-and-output-as-a-png-image.cs @@ -0,0 +1,89 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Rendering; +using Aspose.Cells.Drawing; + +namespace AsposeCellsTimeline3D +{ + class Program + { + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + + // ------------------------------------------------- + // Populate worksheet with sample data (Date + Value) + // ------------------------------------------------- + sheet.Cells["A1"].PutValue("Date"); + sheet.Cells["B1"].PutValue("Value"); + + sheet.Cells["A2"].PutValue(new DateTime(2023, 1, 1)); + sheet.Cells["A3"].PutValue(new DateTime(2023, 2, 1)); + sheet.Cells["A4"].PutValue(new DateTime(2023, 3, 1)); + sheet.Cells["A5"].PutValue(new DateTime(2023, 4, 1)); + + sheet.Cells["B2"].PutValue(120); + sheet.Cells["B3"].PutValue(150); + sheet.Cells["B4"].PutValue(180); + sheet.Cells["B5"].PutValue(210); + + // ------------------------------------------------- + // Create a PivotTable that will be the data source for the Timeline + // ------------------------------------------------- + int pivotIndex = sheet.PivotTables.Add("A1:B5", "D1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIndex]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Value"); + pivot.RefreshData(); + pivot.CalculateData(); + + // ------------------------------------------------- + // Add a Timeline linked to the PivotTable + // ------------------------------------------------- + // Place the Timeline starting at row 10, column 2 (cell B10) + int timelineIndex = sheet.Timelines.Add(pivot, 9, 1, "Date"); + var timeline = sheet.Timelines[timelineIndex]; // Timeline object + + // ------------------------------------------------- + // Apply 3‑D perspective effect to the Timeline shape + // ------------------------------------------------- + var shape = timeline.Shape; // TimelineShape + var threeD = shape.ThreeDFormat; // ThreeDFormat + + // Set perspective angle (0‑120 degrees). 45 gives a moderate 3‑D view. + threeD.Perspective = 45; + + // Adjust depth (distance from the ground) to enhance the 3‑D effect. + threeD.Z = 30; // moves the shape away from the sheet + threeD.ExtrusionHeight = 10; // gives the shape some thickness + + // Optional: rotate for better visual appearance + threeD.RotationX = 20; + threeD.RotationY = 30; + + // ------------------------------------------------- + // Render the worksheet (which now contains the Timeline) to a PNG image + // ------------------------------------------------- + ImageOrPrintOptions renderOptions = new ImageOrPrintOptions + { + ImageType = ImageType.Png, + OnePagePerSheet = true + }; + + SheetRender renderer = new SheetRender(sheet, renderOptions); + // Render the first (and only) page to a file named "Timeline3D.png" + renderer.ToImage(0, "Timeline3D.png"); + } + catch (Exception ex) + { + // Log or display the error details + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/render-a-timeline-with-data-labels-showing-percentages-adjust-label-font-size-and-save-as-png.cs b/timeline/render-a-timeline-with-data-labels-showing-percentages-adjust-label-font-size-and-save-as-png.cs new file mode 100644 index 0000000000..ff4181c743 --- /dev/null +++ b/timeline/render-a-timeline-with-data-labels-showing-percentages-adjust-label-font-size-and-save-as-png.cs @@ -0,0 +1,80 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Charts; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class Program +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate worksheet with sample data (dates, categories, amounts) + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Category"); + cells["C1"].PutValue("Amount"); + + // Define a style for date cells (m/d/yyyy) + Style dateStyle = workbook.CreateStyle(); + dateStyle.Number = 14; // Built‑in date format + + DateTime baseDate = new DateTime(2023, 1, 1); + for (int i = 0; i < 5; i++) + { + cells[1 + i, 0].PutValue(baseDate.AddMonths(i)); // Date + cells[1 + i, 0].SetStyle(dateStyle); // Apply date format + cells[1 + i, 1].PutValue("Item " + (i + 1)); // Category + cells[1 + i, 2].PutValue((i + 1) * 10); // Amount + } + + // Create a pivot table based on the data + PivotTableCollection pivots = sheet.PivotTables; + int pivotIndex = pivots.Add("A1:C6", "E1", "PivotTable1"); + PivotTable pivot = pivots[pivotIndex]; + + // Configure pivot fields + pivot.AddFieldToArea(PivotFieldType.Page, "Date"); // Required for Timeline + pivot.AddFieldToArea(PivotFieldType.Row, "Category"); + pivot.AddFieldToArea(PivotFieldType.Data, "Amount"); + pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium9; + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a Timeline control linked to the pivot table (Date field) + sheet.Timelines.Add(pivot, 12, 0, "Date"); + + // Add a pie chart that will display percentages in data labels + int chartIndex = sheet.Charts.Add(ChartType.Pie, 20, 0, 35, 15); + Chart chart = sheet.Charts[chartIndex]; + chart.NSeries.Add("C2:C6", true); + chart.NSeries.CategoryData = "A2:A6"; + + // Enable data labels and configure them to show percentages + DataLabels dataLabels = chart.NSeries[0].DataLabels; + dataLabels.ShowPercentage = true; // display percentage values + dataLabels.ShowValue = false; // hide raw values + dataLabels.Font.Size = 14; // set desired font size + dataLabels.ApplyFont(); // apply the font settings to all labels + + // Ensure output directory exists + string outputPath = "TimelineChart.png"; + string outputDir = Path.GetDirectoryName(outputPath); + if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir)) + Directory.CreateDirectory(outputDir); + + // Render the worksheet (including the timeline and chart) to a PNG image + workbook.Save(outputPath, SaveFormat.Png); + } + catch (Exception ex) + { + Console.WriteLine("Error: " + ex.Message); + } + } +} \ No newline at end of file diff --git a/timeline/render-a-timeline-with-shadow-effects-adjust-opacity-and-output-the-image-as-a-png-with-transparency.cs b/timeline/render-a-timeline-with-shadow-effects-adjust-opacity-and-output-the-image-as-a-png-with-transparency.cs new file mode 100644 index 0000000000..8d3e59ca2d --- /dev/null +++ b/timeline/render-a-timeline-with-shadow-effects-adjust-opacity-and-output-the-image-as-a-png-with-transparency.cs @@ -0,0 +1,91 @@ +using System; +using Aspose.Cells; +using Aspose.Cells.Rendering; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; +using Aspose.Cells.Drawing; + +namespace AsposeCellsTimelineRender +{ + public class RenderTimelineWithShadow + { + public static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate worksheet with sample data (including a date column) + cells[0, 0].Value = "Fruit"; + cells[0, 1].Value = "Date"; + cells[0, 2].Value = "Amount"; + + cells[1, 0].Value = "Apple"; + cells[1, 1].Value = new DateTime(2021, 2, 5); + cells[1, 2].Value = 120; + + cells[2, 0].Value = "Orange"; + cells[2, 1].Value = new DateTime(2022, 3, 8); + cells[2, 2].Value = 150; + + cells[3, 0].Value = "Banana"; + cells[3, 1].Value = new DateTime(2023, 4, 10); + cells[3, 2].Value = 180; + + // Create a PivotTable based on the data + PivotTableCollection pivots = sheet.PivotTables; + int pivotIdx = pivots.Add("=Sheet1!A1:C4", "E5", "FruitPivot"); + PivotTable pivot = pivots[pivotIdx]; + pivot.AddFieldToArea(PivotFieldType.Row, "Fruit"); + pivot.AddFieldToArea(PivotFieldType.Column, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Amount"); + + // Add the Date field as a Page (filter) field – required for Timeline creation + pivot.AddFieldToArea(PivotFieldType.Page, "Date"); + + pivot.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium10; + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a Timeline linked to the PivotTable's date field + sheet.Timelines.Add(pivot, 15, 0, "Date"); + Timeline timeline = sheet.Timelines[0]; + + // Configure timeline appearance + timeline.Caption = "Sales Timeline"; + timeline.ShowHeader = true; + timeline.ShowHorizontalScrollbar = true; + + // Apply shadow effect to the underlying shape + TimelineShape timelineShape = timeline.Shape; + ShadowEffect shadow = timelineShape.ShadowEffect; + shadow.Angle = 135; // direction of the shadow + shadow.Blur = 20; // blur radius + shadow.Size = 1.0; // size multiplier + shadow.Distance = 10; // distance from the shape + shadow.Transparency = 0.4; // 40% transparent shadow + + // Set image rendering options: PNG format with transparent background + ImageOrPrintOptions imgOptions = new ImageOrPrintOptions + { + ImageType = ImageType.Png, + Transparent = true + }; + + // Render the worksheet (including the timeline) to a PNG image + SheetRender renderer = new SheetRender(sheet, imgOptions); + string outputPath = "TimelineWithShadow.png"; + renderer.ToImage(0, outputPath); + + Console.WriteLine($"Timeline rendered to image with shadow and transparency: {outputPath}"); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } + } +} \ No newline at end of file diff --git a/timeline/update-an-existing-timeline-by-adding-a-new-data-series-and-rerender-it-to-a-pdf-with-annotations.cs b/timeline/update-an-existing-timeline-by-adding-a-new-data-series-and-rerender-it-to-a-pdf-with-annotations.cs new file mode 100644 index 0000000000..b3077509b8 --- /dev/null +++ b/timeline/update-an-existing-timeline-by-adding-a-new-data-series-and-rerender-it-to-a-pdf-with-annotations.cs @@ -0,0 +1,81 @@ +using System; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Charts; +using Aspose.Cells.Timelines; +using Aspose.Cells.Drawing; + +class UpdateTimelineAndExportPdf +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate sample data: Date, Sales, Profit + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Sales"); + cells["C1"].PutValue("Profit"); + DateTime startDate = new DateTime(2023, 1, 1); + for (int i = 0; i < 5; i++) + { + cells[i + 1, 0].PutValue(startDate.AddMonths(i)); + cells[i + 1, 1].PutValue(1000 + i * 200); // Sales + cells[i + 1, 2].PutValue(200 + i * 50); // Profit + } + + // Create a pivot table using the data range + int pivotIdx = sheet.PivotTables.Add("A1:C6", "E1", "PivotTable1"); + PivotTable pivot = sheet.PivotTables[pivotIdx]; + + // Place the Date field in the column area (required for Timeline) + pivot.AddFieldToArea(PivotFieldType.Column, "Date"); + // Add Sales and Profit as data fields + pivot.AddFieldToArea(PivotFieldType.Data, "Sales"); + pivot.AddFieldToArea(PivotFieldType.Data, "Profit"); + + // Refresh and calculate the pivot table + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a timeline linked to the Date field of the pivot table + int timelineIdx = sheet.Timelines.Add(pivot, "G1", "Date"); + Timeline timeline = sheet.Timelines[timelineIdx]; + timeline.Caption = "Sales & Profit Timeline"; + timeline.Name = "SalesProfitTimeline"; + + // Create a column chart based on the pivot table data + int chartIdx = sheet.Charts.Add(ChartType.Column, 15, 0, 30, 15); + Chart chart = sheet.Charts[chartIdx]; + + // First series: Sales + chart.NSeries.Add("=PivotTable1!Sales", true); + // Second series: Profit + chart.NSeries.Add("=PivotTable1!Profit", true); + // Category (X‑axis) data: Date + chart.NSeries.CategoryData = "=PivotTable1!Date"; + chart.Title.Text = "Sales and Profit Over Time"; + + // Add a textbox annotation to the worksheet + Shape annotation = sheet.Shapes.AddTextBox(5, 0, 5, 0, 200, 50); + annotation.Text = "Generated on " + DateTime.Now.ToString("yyyy-MM-dd"); + annotation.Font.Size = 10; + annotation.Font.Color = System.Drawing.Color.Blue; + + // Export the chart (which includes the timeline) to PDF + chart.ToPdf("TimelineChart.pdf"); + + // Save the workbook (optional, for verification) + workbook.Save("TimelineWithChart.xlsx"); + } + catch (Exception ex) + { + Console.WriteLine("Error: " + ex.Message); + } + } +} \ No newline at end of file diff --git a/timeline/validate-timeline-date-ranges-against-a-predefined-calendar-and-log-any-inconsistencies-to-a-text-file.cs b/timeline/validate-timeline-date-ranges-against-a-predefined-calendar-and-log-any-inconsistencies-to-a-text-file.cs new file mode 100644 index 0000000000..0c9b655abf --- /dev/null +++ b/timeline/validate-timeline-date-ranges-against-a-predefined-calendar-and-log-any-inconsistencies-to-a-text-file.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.IO; +using Aspose.Cells; +using Aspose.Cells.Pivot; +using Aspose.Cells.Timelines; + +class TimelineDateRangeValidator +{ + static void Main() + { + try + { + // Create a new workbook and get the first worksheet + Workbook workbook = new Workbook(); + Worksheet sheet = workbook.Worksheets[0]; + Cells cells = sheet.Cells; + + // Populate sample data with dates and sales values + cells["A1"].PutValue("Date"); + cells["B1"].PutValue("Sales"); + + DateTime[] sampleDates = { + new DateTime(2023, 1, 1), + new DateTime(2023, 1, 5), + new DateTime(2023, 2, 10), // Outside the allowed calendar + new DateTime(2023, 1, 20) + }; + + int[] sampleSales = { 100, 200, 300, 400 }; + + for (int i = 0; i < sampleDates.Length; i++) + { + cells[i + 1, 0].PutValue(sampleDates[i]); + cells[i + 1, 1].PutValue(sampleSales[i]); + } + + // Create a pivot table using the date column as a row field + PivotTableCollection pivots = sheet.PivotTables; + int pivotIdx = pivots.Add("A1:B5", "D1", "PivotTable1"); + PivotTable pivot = pivots[pivotIdx]; + pivot.AddFieldToArea(PivotFieldType.Row, "Date"); + pivot.AddFieldToArea(PivotFieldType.Data, "Sales"); + + // Refresh and calculate the pivot table + pivot.RefreshData(); + pivot.CalculateData(); + + // Add a Timeline control linked to the Date field of the pivot table + sheet.Timelines.Add(pivot, "F1", "Date"); + Timeline timeline = sheet.Timelines[0]; + + // Define a predefined calendar (e.g., all dates in January 2023) + HashSet allowedDates = new HashSet(); + DateTime calStart = new DateTime(2023, 1, 1); + DateTime calEnd = new DateTime(2023, 1, 31); + for (DateTime d = calStart; d <= calEnd; d = d.AddDays(1)) + allowedDates.Add(d.Date); + + // Log dates that are outside the allowed calendar + string logFilePath = "DateInconsistencies.txt"; + using (StreamWriter writer = new StreamWriter(logFilePath, false)) + { + for (int row = 1; row <= sampleDates.Length; row++) + { + object cellValue = cells[row, 0].Value; + if (cellValue is DateTime dt && !allowedDates.Contains(dt.Date)) + writer.WriteLine($"Row {row + 1}: Date {dt:yyyy-MM-dd} is outside the allowed calendar."); + } + } + + // Save the workbook with the Timeline + string outputPath = "TimelineValidated.xlsx"; + workbook.Save(outputPath); + Console.WriteLine($"Workbook saved to '{outputPath}'."); + } + catch (Exception ex) + { + Console.WriteLine($"Error: {ex.Message}"); + } + } +} \ No newline at end of file