diff --git a/lib/src/office/excel.dart b/lib/src/office/excel.dart index 77510c1..8f48be2 100644 --- a/lib/src/office/excel.dart +++ b/lib/src/office/excel.dart @@ -1,18 +1,27 @@ library excel; import 'package:js/js.dart'; +import 'package:flutter/material.dart'; + +import 'dart:typed_data'; +import 'package:flutter/services.dart'; +import 'dart:convert'; +import 'dart:async'; import './office_extension.dart' as office_extension; import '../abstract/js_object_wrapper.dart'; import '../js_interops/es6_js_impl.dart' as js; import '../js_interops/office_helpers_js_impl.dart'; import '../office_interops/excel_js_impl.dart' as excel_js; +import '../office_interops/excel_js_impl.dart'; import '../utils/interop_utils.dart'; import 'models/excel_models.dart'; class Excel { Excel._(); + static RequestContext? _context; + // static Future run() async { // if (_context != null) return _context!; @@ -41,6 +50,62 @@ class Excel { return RequestContext.getInstance(contextJs); } + + static Future copySheetsFromAsset( + String assetPath, { + BuildContext? buildContext, + }) async { + String message = ''; + bool haveError = false; + try { + final context = await run(); + + await context.sync(); + final workbook = context.workbook; + + final ByteData byteData = await rootBundle.load(assetPath); + message += 'Loaded\n'; + final List bytes = byteData.buffer.asUint8List(); + message += 'Converted\n'; + final String base64Data = base64Encode(bytes); + message += '\n\n${base64Data}\n\n'; + message += 'Finalised\n'; + + final options = { + 'sheetNamesToInsert': [], + // Insert all sheets from the source workbook. + 'positionType': 'after', + // Insert after the `relativeTo` sheet. + 'relativeTo': 'Sheet1', + // The sheet relative to which the other sheets will be inserted. + }; + + await workbook.insertWorksheetsFromBase64(base64Data, options); + message += 'Passed to JS\n'; + + await context.sync(); + message += 'Excel Synced\n'; + } catch (error) { + print(error); + haveError = true; + if (buildContext != null) { + await showDialog( + context: buildContext, + builder: (BuildContext) { + return SelectableText( + 'Error in copySheetsFromAsset:\n${message} \n${error}'); + }); + } + } + + if (buildContext != null && haveError == false) { + await showDialog( + context: buildContext, + builder: (BuildContext) { + return SelectableText('Info \n${message} '); + }); + } + } } class RequestContext extends JsObjectWrapper { @@ -93,6 +158,70 @@ class Workbook extends office_extension.ClientObject { Worksheet load(final List propertyNames) => Worksheet.getInstance(jsObject.load(propertyNames)); + + //new code + // Add a method for duplicating a worksheet + Future duplicateSheetBackup(String originalSheetName, + {String? newSheetName} /*{String? beforeSheetName}*/) async { + // Get the RequestContext from the current Workbook instance + final RequestContext context = this.context; + + try { + // Get the original worksheet to copy + Worksheet sheetToCopy = + context.workbook.worksheets.getItem(originalSheetName); + // Load the name property + sheetToCopy.load(['name']); + + // Run the sync to load the property + await context.sync(); + + // Add a new worksheet + Worksheet newSheet = await context.workbook.worksheets + .add(newSheetName ?? (sheetToCopy.name + ' Copy')); + // Load the position property in case you need to reposition the sheet + newSheet.load(['position']); + + // if (beforeSheetName != null) { + // newSheet.position = worksheets.getItem(beforeSheetName).position; + // // Load the position property + // beforeSheet.load(['position']); + // } + + // Sync the operations above + await context.sync(); + + // if (beforeSheetName != null) { + // // Update the position of the new sheet + // Worksheet beforeSheet = context.workbook.worksheets.getItem(beforeSheetName); + // newSheet.position = beforeSheet.position; + // // Ensure the position property is set in the batch + // newSheet.load(['position']); + // } + + // Final sync to ensure all pending operations complete + await context.sync(); + } catch (error) { + print('Error duplicating worksheet: $error'); + throw error; + } + } + + Future insertWorksheetsFromBase64( + String base64Data, Map options) async { + final completer = Completer(); + + try { + // await jsObject.context.sync(); + await jsObject.insertWorksheetsFromBase64(base64Data, options); + // await jsObject.context.sync(); + completer.complete(); + } catch (e) { + completer.completeError(e); + } + + return completer.future; + } } class WorksheetCollection @@ -161,6 +290,40 @@ class WorksheetCollection WorksheetCollection load(final List propertyNames) { return WorksheetCollection.getInstance(jsObject.load(propertyNames)); } + + Future add(String worksheetName) async { + final context = this.context; + final newWorksheet = this.jsObject.add(worksheetName); + await context.sync(); + return Worksheet.getInstance(newWorksheet); + } + + // Future> addFromBase64({ + // required String base64File, + // List? sheetNamesToInsert, + // String? positionTypeString, + // dynamic relativeTo, + // }) async { + // try{ + // final relativeToObject = + // relativeTo is Worksheet ? relativeTo.jsObject : relativeTo; + // + // final clientResult = await jsObject.addFromBase64( + // base64File, + // sheetNamesToInsert, + // positionTypeString, + // relativeToObject + // ); + // + // // Context sync is assumed to be called outside or handled within a batch operation. + // await context.sync(); + // + // // Assuming ClientResultJsImpl is the correct type that corresponds to OfficeExtension.ClientResult + // return clientResult; + // }catch(e){ + // return e; + // } + // } } class Worksheet @@ -218,6 +381,11 @@ class Worksheet Worksheet.getInstance(jsObject.load(propertyNames)); void activate() => jsObject.activate(); + + Range getUsedRange() { + final jsRange = jsObject.getUsedRange(); + return Range._fromJsObject(jsRange); + } } class Range extends office_extension.ClientObject { @@ -261,6 +429,21 @@ class Range extends office_extension.ClientObject { Range getLastColumn() => Range._fromJsObject(jsObject.getLastColumn()); Range getLastCell() => Range._fromJsObject(jsObject.getLastCell()); + Future clear(String v) async { + // Ensure context is synced before using the range + await context.sync(); + + // Call clear method on the range + jsObject.clear(v); + + // Ensure changes are synchronized with the workbook + await context.sync(); + } + + Future delete(String shiftDirection) async { + jsObject.delete(shiftDirection); + } + Range getColumn(final int column) => Range._fromJsObject(jsObject.getColumn(column)); @@ -283,6 +466,129 @@ class Range extends office_extension.ClientObject { jsObject.values = values; RangeFormat get format => RangeFormat._fromJsObject(jsObject.format); + + //new code starts + + Future insert(String direction) async { + jsObject.insert(direction); + } + + //code to find matches + +//new code ends + +// Dart-friendly wrapper for the find method + Range find(String text, + {bool completeMatch = false, + bool matchCase = false, + String searchDirection = 'Forward'}) { + // Create the options object + var options = { + 'completeMatch': completeMatch, + 'matchCase': matchCase, + 'searchDirection': searchDirection + }; + + // Call the find method on the underlying JS object + var foundRangeJsImpl = jsObject.find(text, options); + + // Return a new Range instance wrapping the found RangeJsImpl + return Range.getInstance(foundRangeJsImpl); + } + + // Implement a find and replace functionality method + Future findAndReplace({ + required String searchText, + required String replaceText, + bool matchCase = false, + bool completeMatch = false, + }) async { + // Define search options + var options = { + 'completeMatch': completeMatch, + 'matchCase': matchCase, + 'searchDirection': 'Forward', // Or 'Backward' + }; + + // Enter the loop: find and replace all occurrences + while (true) { + var foundRangeJsImpl = jsObject.find(searchText, options); + + // Null check based on Office.js Promise-like callback pattern + if (foundRangeJsImpl == null) { + // No more appearances are found, exit the loop + break; + } + + // Get the Dart Range instance from the found JavaScript range object + Range foundRange = Range.getInstance(foundRangeJsImpl); + + // Replace the text in the found range and load its address + foundRange.values = [ + [replaceText] + ]; + foundRange.load([ + 'address' + ]); // Optional, if you want to check where the replacement took place + + // Synchronize changes to the Excel workbook + await context.sync(); + + // Optionally, print the address of the replaced range (if you had loaded it earlier) + // print(foundRange.address); + } + } + + // Method to load the address property + Future loadAddress() async { + // Queue up a command to load the address property + jsObject.load(['address']); + + // Run the queued-up command, and return a promise to indicate task completion + await context.sync(); + + // Return the address property + return jsObject.address; + } + + // Method to activate (select) the range in the Excel workbook + Future activate() async { + // Call the 'select' method on the range + jsObject.select(); + + // Since 'select' is an action that affects the state of the workbook interface, + // you should ensure any pending commands are synchronized with the Excel workbook + await context.sync(); + } + + // Method to find a string and activate (select) the range where it's found + Future findAndActivate(String searchText, + {bool matchCase = false, bool completeMatch = false}) async { + // Object to specify search options + final options = { + 'completeMatch': completeMatch, + 'matchCase': matchCase, + 'searchDirection': 'Forward', + }; + + // Find the text in the range + final foundRangeJsImpl = jsObject.find(searchText, options); + + // Before using foundRangeJsImpl, you may need a mechanism to ensure it's not null. + // if (foundRangeJsImpl == null) { + // // Handle the scenario where the text is not found + // return; + // } + // Wrap the JavaScript Range object with the Dart Range object + final foundRange = Range._fromJsObject(foundRangeJsImpl); + + // Activate the found range + await foundRange.activate(); + } + + void copyFrom(List> data) { + jsObject.copyFrom(data); + } } class RangeFormat @@ -303,4 +609,122 @@ class RangeFormat bool get wrapText => jsObject.wrapText; set wrapText(final bool value) => jsObject.wrapText = value; + + //new code starts +// Alignment + + // Font + bool get bold => jsObject.font.bold; + set bold(final bool value) => jsObject.font.bold = value; + + bool get italic => jsObject.font.italic; + set italic(final bool value) => jsObject.font.italic = value; + + String get fontColor => jsObject.font.color; + set fontColor(final String value) => jsObject.font.color = value; + + String get fontName => jsObject.font.name; + set fontName(final String value) => jsObject.font.name = value; + + num get fontSize => jsObject.font.size; + set fontSize(final num value) => jsObject.font.size = value; + + // Fill + String get fillBackgroundColor => jsObject.fill.color; + set fillBackgroundColor(final String value) => jsObject.fill.color = value; + + String get fillPattern => jsObject.fill.pattern; + set fillPattern(final String value) => jsObject.fill.pattern = value; + + // Borders + + Borders get borders => Borders.getInstance(jsObject.borders); + set borders(Borders value) => jsObject.borders = value.jsObject; +//border code ends + +} + +class RangeBorder extends office_extension.ClientObject { + RangeBorder._fromJsObject(super.jsObject); + + factory RangeBorder.getInstance(excel_js.BorderJsImpl jsObject) { + return _expando[jsObject] ??= RangeBorder._fromJsObject(jsObject); + } + static final _expando = Expando(); + + RequestContext get context => RequestContext.getInstance(jsObject.context); + + String get color => jsObject.color; + set color(String value) => jsObject.color = value; + + String get style => jsObject.style; + set style(String value) => jsObject.style = value; +} + +class Borders extends office_extension.ClientObject { + Borders._fromJsObject(excel_js.BordersJsImpl jsObject) : super(jsObject); + + factory Borders.getInstance(excel_js.BordersJsImpl jsObject) { + return _expando[jsObject] ??= Borders._fromJsObject(jsObject); + } + static final _expando = Expando(); + + RequestContext get context => RequestContext.getInstance(jsObject.context); + + // Method to get a specific border by its side index + RangeBorder getItem(String sideIndex) { + var borderJsImpl = jsObject.getItem(sideIndex); + return RangeBorder.getInstance(borderJsImpl); + } + + RangeBorder? get top => + jsObject.top != null ? RangeBorder.getInstance(jsObject.top!) : null; + set top(RangeBorder? value) => jsObject.top = value?.jsObject; + + RangeBorder? get bottom => jsObject.bottom != null + ? RangeBorder.getInstance(jsObject.bottom!) + : null; + set bottom(RangeBorder? value) => jsObject.bottom = value?.jsObject; + + RangeBorder? get left => + jsObject.left != null ? RangeBorder.getInstance(jsObject.left!) : null; + set left(RangeBorder? value) => jsObject.left = value?.jsObject; + + RangeBorder? get right => + jsObject.right != null ? RangeBorder.getInstance(jsObject.right!) : null; + set right(RangeBorder? value) => jsObject.right = value?.jsObject; +} + +//new font class definition +class Font extends office_extension.ClientObject { + Font._fromJsObject(super.jsObject); + + /// Creates a [Font] from a [jsObject]. + /// + /// {@macro expando_explanation} + factory Font.getInstance(final excel_js.FontJsImpl jsObject) { + return _expando[jsObject] ??= Font._fromJsObject(jsObject); + } + + static final _expando = Expando(); + + /// Gets or sets a value that represents the bold status of the font. + bool get bold => jsObject.bold; + set bold(bool value) => jsObject.bold = value; + + /// Gets or sets a value that represents the italic status of the font. + bool get italic => jsObject.italic; + set italic(bool value) => jsObject.italic = value; + + /// Gets or sets the color of the given font. + String get fontColor => jsObject.color; + set fontColor(String value) => jsObject.color = value; + + /// Gets or sets the name of the font. + String get fontName => jsObject.name; + set fontName(String value) => jsObject.name = value; + + /// Gets or sets the size of the font in points. + num get fontSize => jsObject.size; + set fontSize(num value) => jsObject.size = value; } diff --git a/lib/src/office_interops/excel_js_impl.dart b/lib/src/office_interops/excel_js_impl.dart index 49f8451..9731897 100644 --- a/lib/src/office_interops/excel_js_impl.dart +++ b/lib/src/office_interops/excel_js_impl.dart @@ -47,6 +47,10 @@ abstract class WorkbookJsImpl extends office_extension_js.ClientObjectJsImpl { /// specify the properties to load. /// external WorksheetJsImpl load(final List propertyNames); + + external Future insertWorksheetsFromBase64( + String base64Data, Map options); + // external Future addFromBase64(String base64Data, Map options); } @JS('WorksheetCollection') @@ -156,6 +160,23 @@ abstract class WorksheetCollectionJsImpl /// @param propertyNames A comma-delimited string or an array of strings /// that specify the properties to load. external WorksheetCollectionJsImpl load(final List propertyNames); + + /// @param worksheetName The name of the new worksheet. + external WorksheetJsImpl add(String worksheetName); + + // /// Inserts the specified worksheets of a workbook into the current workbook. + // /// @param base64File The base64-encoded string representing the source workbook file. + // /// @param sheetNamesToInsert The names of individual worksheets to insert. + // /// @param positionTypeString Where in the current workbook the new worksheets will be inserted. + // /// ("None" | "Before" | "After" | "Beginning" | "End") + // /// @param relativeTo The worksheet in the current workbook that is referenced for the positionType parameter. + // external Future> addFromBase64( + // String base64File, + // [List? sheetNamesToInsert, + // String? positionTypeString, // should be one of the specified values or null + // dynamic /* WorksheetJsImpl | String */ relativeTo + // ] + // ); } @JS('Worksheet') @@ -244,6 +265,8 @@ abstract class WorksheetJsImpl extends office_extension_js.ClientObjectJsImpl { final int rowCount, final int columnCount, ); + + external RangeJsImpl getUsedRange(); } /// Range represents a set of one or more contiguous cells such as a cell, @@ -391,8 +414,76 @@ abstract class RangeJsImpl extends office_extension_js.ClientObjectJsImpl { /// @remarks /// [Api set: ExcelApi 1.1] external RangeFormatJsImpl get format; + + //new clear code + external Future clear(String v); + // Add the following method to the RangeJsImpl class + external Future delete(String shiftDirection); + + external Future insert(String direction); + + //new code + + // Add a method to find a value within the range + external RangeJsImpl find(String text, [dynamic options]); + + external String get address; + +//new code end + // Externally define the 'select' JavaScript method, which will be called from Dart + external Future select(); + + external void copyFrom(List> data); } +//adding new font classes code here + +//font class definition +@JS('Font') +abstract class FontJsImpl extends office_extension_js.ClientObjectJsImpl { + /// The request context associated with the object. This connects + /// the add-in's process to the Office host application's process. + @override + external RequestContextJsImpl get context; + + /// Gets or sets a value that represents the bold status of the font. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external bool get bold; + external set bold(bool value); + + /// Gets or sets a value that represents the italic status of the font. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external bool get italic; + external set italic(bool value); + + /// Gets or sets the color of the given font. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external String get color; + external set color(String value); + + /// Gets or sets the name of the font. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external String get name; + external set name(String value); + + /// Gets or sets the size of the font in points. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external num get size; + external set size(num value); +} + +//end font style code here + /// A format object encapsulating the range's font, fill, borders, /// alignment, and other properties. /// @@ -414,4 +505,54 @@ abstract class RangeFormatJsImpl /// [Api set: ExcelApi 1.1] external bool get wrapText; external set wrapText(final bool value); + + //new code starts + + external FontJsImpl get font; + external set font(FontJsImpl value); + + external dynamic get fill; + external set fill(dynamic value); + + external dynamic get numberFormat; + external set numberFormat(dynamic value); + + external dynamic get protection; + external set protection(dynamic value); + //new code ends + + external BordersJsImpl get borders; + external set borders(BordersJsImpl value); +} + +@JS('Border') +abstract class BorderJsImpl extends office_extension_js.ClientObjectJsImpl { + @override + external RequestContextJsImpl get context; + + external dynamic get color; + external set color(dynamic value); + + external dynamic get style; + external set style(dynamic value); +} + +@JS('Borders') +abstract class BordersJsImpl extends office_extension_js.ClientObjectJsImpl { + @override + external RequestContextJsImpl get context; + + external BorderJsImpl getItem(String sideIndex); + + external BorderJsImpl? get top; + external set top(BorderJsImpl? value); + + external BorderJsImpl? get bottom; + external set bottom(BorderJsImpl? value); + + external BorderJsImpl? get left; + external set left(BorderJsImpl? value); + + external BorderJsImpl? get right; + external set right(BorderJsImpl? value); } diff --git a/lib/src/office_interops/office_js_impl.dart b/lib/src/office_interops/office_js_impl.dart index bf9ab51..f54c887 100644 --- a/lib/src/office_interops/office_js_impl.dart +++ b/lib/src/office_interops/office_js_impl.dart @@ -1,109 +1,521 @@ -@JS('Office') -library office_js; +// ignore_for_file: avoid_positional_boolean_parameters + +@JS('Excel') +library excel_js; import 'package:js/js.dart'; -/// Represents the runtime environment of the add-in and provides -/// access to key objects of the API. -/// The current context exists as a property of Office. -/// It is accessed using `Office.context`. -/// -/// @remarks -/// -/// **Applications**: Excel, Outlook, PowerPoint, Project, Word -/// -@JS('Context') -abstract class ContextJsImpl { - /// Provides access to the Microsoft Outlook add-in object model. + +import 'office_core_js_impl.dart' as office_core_js; +import 'office_extension_js_impl.dart' as office_extension_js; + + + +/// The RequestContext object facilitates requests to the Excel application. +/// Since the Office add-in and the Excel application run in +/// two different processes, the request context is required +/// to get access to the Excel object model from the add-in. +@JS('RequestContext') +abstract class RequestContextJsImpl + extends office_core_js.RequestContextJsImpl { + external WorkbookJsImpl get workbook; + + /// Collection of objects that are tracked for automatic adjustments based + /// on surrounding changes in the document. + external office_extension_js.TrackedObjectsJsImpl get trackedObjects; +} + +@JS('Workbook') +abstract class WorkbookJsImpl extends office_extension_js.ClientObjectJsImpl { + /// The request context associated with the object. This connects + /// the add-in's process to the Office host application's process. */ + @override + external RequestContextJsImpl get context; + + /// Represents a collection of worksheets associated with the workbook. + /// + /// Api set: ExcelApi 1.1 + external WorksheetCollectionJsImpl get worksheets; + + /// Gets the workbook name. /// /// @remarks + /// Api set: ExcelApi 1.7 + external String get name; + + /// Queues up a command to load the specified properties of the object. + /// You must call `context.sync()` before reading the properties. /// - /// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/understanding-outlook-add-in-permissions | Minimum permission level}**: **restricted** + /// @param propertyNames A comma-delimited string or an array of strings that + /// specify the properties to load. /// - /// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points | Applicable Outlook mode}**: Compose or Read + external WorksheetJsImpl load(final List propertyNames); +} + +@JS('WorksheetCollection') +abstract class WorksheetCollectionJsImpl + extends office_extension_js.ClientObjectJsImpl { + /// The request context associated with the object. This connects + /// the add-in's process to the Office host application's process. */ + @override + external RequestContextJsImpl get context; + + /// Gets the loaded child items in this collection. */ + external List get items; + + /// Gets the number of worksheets in the collection. + /// + /// Api set: ExcelApi 1.4 /// - /// **Key properties**: + /// @param visibleOnly Optional. If `true`, considers only visible + /// worksheets, skipping over any hidden ones. + external office_extension_js.ClientResultJsImpl getCount([ + final bool? visibleOnly, + ]); + + /// Gets the first worksheet in the collection. /// - /// - `diagnostics`: Provides diagnostic information to an Outlook add-in. + /// Api set: ExcelApi 1.5 + /// + /// @param visibleOnly Optional. If `true`, considers only visible + /// worksheets, skipping over any hidden ones. + external WorksheetJsImpl getFirst(final bool? visibleOnly); + + /// Occurs when any worksheet in the workbook is activated. + /// [Api set: ExcelApi 1.7] /// - /// - `item`: Provides methods and properties for accessing a message or - /// appointment in an Outlook add-in. + /// @eventproperty /// - /// - `userProfile`: Provides information about the user in an Outlook add-in. - external MailboxJsImpl get mailbox; + /// To get proper type convert to [WorksheetActivatedEventArgs] + external office_extension_js.EventHandlersJsImpl get onActivated; + + /// Occurs when a new worksheet is added to the workbook. + /// + /// Api set: ExcelApi 1.7 + /// + /// @eventproperty + /// + /// To get proper type convert to [WorksheetAddedEventArgs] + external office_extension_js.EventHandlersJsImpl get onAdded; + + /// Occurs when a worksheet is deleted from the workbook. + /// + /// [Api set: ExcelApi 1.7] + /// + /// @eventproperty + /// + /// To get proper type convert to [WorksheetDeletedEventArgs] + external office_extension_js.EventHandlersJsImpl get onDeleted; + + /// Occurs when any worksheet in the workbook is changed. + /// + /// [Api set: ExcelApi 1.9] + /// + /// @eventproperty + /// + /// To get proper type convert to [WorksheetChangedEventArgs] + external office_extension_js.EventHandlersJsImpl get onChanged; + + /// Occurs when the worksheet name is changed. + /// + /// @remarks + /// [Api set: ExcelApiOnline 1.1] + /// + /// @eventproperty + /// + /// To get proper type convert to [WorksheetNameChangedEventArgs] + external office_extension_js.EventHandlersJsImpl get onNameChanged; + + /// Occurs when a worksheet is moved within a workbook. + /// This event only triggers when a worksheet is directly + /// moved within a workbook. This event doesn't trigger when + /// the position of a worksheet is indirectly changed, such + /// as when a new worksheet is inserted and causes existing + /// worksheets to change positions. + /// + /// @remarks + /// [Api set: ExcelApiOnline 1.1] + /// + /// @eventproperty + /// To get proper type convert to [WorksheetMovedEventArgs] + external office_extension_js.EventHandlersJsImpl get onMoved; + + /// Gets a worksheet object using its name or ID. + /// + /// Api set: ExcelApi 1.1 + /// + /// @param key The name or ID of the worksheet. + //// + external WorksheetJsImpl getItem(final String key); + + /// Gets the currently active worksheet in the workbook. + /// + /// Api set: ExcelApi 1.1 + external WorksheetJsImpl getActiveWorksheet(); + + /// Queues up a command to load the specified properties of the object. + /// You must call `context.sync()` before reading the properties. + /// + /// @param propertyNames A comma-delimited string or an array of strings + /// that specify the properties to load. + external WorksheetCollectionJsImpl load(final List propertyNames); } -/// Provides access to the Microsoft Outlook add-in object model. -/// -/// Key properties: -/// -/// - `diagnostics`: Provides diagnostic information to an Outlook add-in. -/// -/// - `item`: Provides methods and properties for accessing a message or -/// appointment in an Outlook add-in. -/// -/// - `userProfile`: Provides information about the user in an Outlook add-in. -/// -/// @remarks -/// -/// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/understanding-outlook-add-in-permissions | Minimum permission level}**: **restricted** -/// -/// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points | Applicable Outlook mode}**: Compose or Read -@JS('Mailbox') -abstract class MailboxJsImpl { - /// The mailbox item. Depending on the context in which the add-in opened, - /// the item type may vary. - /// If you want to see IntelliSense for only a specific type or mode, - /// cast this item to one of the following: - /// - /// {@link Office.MessageCompose | MessageCompose}, - /// {@link Office.MessageRead | MessageRead}, - /// {@link Office.AppointmentCompose | AppointmentCompose}, - /// {@link Office.AppointmentRead | AppointmentRead} - /// - /// **Important**: `item` can be null if your add-in supports - /// pinning the task pane. For details on how to handle, see - /// {@link https://learn.microsoft.com/office/dev/add-ins/outlook/pinnable-taskpane#implement-the-event-handler - /// | Implement a pinnable task pane in Outlook}. - external ItemJsImpl? get item; +@JS('Worksheet') +abstract class WorksheetJsImpl extends office_extension_js.ClientObjectJsImpl { + /// The request context associated with the object. This connects + /// the add-in's process to the Office host application's process. */ + @override + external RequestContextJsImpl get context; + + /// The display name of the worksheet. + /// + /// Api set: ExcelApi 1.1 + external String get name; + external set name(final String value); + + /// Returns a value that uniquely identifies the worksheet + /// in a given workbook. The value of the identifier remains the same + /// even when the worksheet is renamed or moved. + /// + /// Api set: ExcelApi 1.1 + external String get id; + + /// The zero-based position of the worksheet within the workbook. + /// + /// Api set: ExcelApi 1.1 + external int get position; + external set position(final int value); + + /// Specifies if gridlines are visible to the user. + /// + /// Api set: ExcelApi 1.8 + external bool get showGridlines; + external set showGridlines(final bool value); + + /// The tab color of the worksheet. + /// + /// When retrieving the tab color, if the worksheet is invisible, + /// the value will be `null`. If the worksheet is visible but + /// the tab color is set to auto, an empty string will be returned. + /// Otherwise, the property will be set to a color, + /// in the form #RRGGBB (e.g., "FFA500"). + /// + /// When setting the color, use an empty-string to set an "auto" color, + /// or a real color otherwise. + /// + /// Api set: ExcelApi 1.7 + external String? get tabColor; + external set tabColor(final String? value); + + /// Queues up a command to load the specified properties of the object. + /// You must call `context.sync()` before reading the properties. + /// + /// @param propertyNames A comma-delimited string or an array of strings + /// that specify the properties to load. + external WorksheetJsImpl load(final List propertyNames); + + /// Activate the worksheet in the Excel UI. + /// + /// Api set: ExcelApi 1.1 + external void activate(); + + /// Gets the `Range` object containing the single cell based on row and + /// column numbers. The cell can be outside the bounds of its parent range, + /// so long as it stays within the worksheet grid. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + /// + /// @param row The row number of the cell to be retrieved. Zero-indexed. + /// @param column The column number of the cell to be retrieved. Zero-indexed. + external RangeJsImpl getCell(final int row, final int column); + + /// Gets the `Range` object beginning at a particular row index and + /// column index, and spanning a certain number of rows and columns. + /// + /// @remarks + /// [Api set: ExcelApi 1.7] + /// + /// @param startRow Start row (zero-indexed). + /// @param startColumn Start column (zero-indexed). + /// @param rowCount Number of rows to include in the range. + /// @param columnCount Number of columns to include in the range. + external RangeJsImpl getRangeByIndexes( + final int startRow, + final int startColumn, + final int rowCount, + final int columnCount, + ); } -/// The item namespace is used to access the currently selected message, -/// meeting request, or appointment. -/// You can determine the type of the item by using the `itemType` property. -/// -/// To see the full member list, refer to the -/// {@link https://learn.microsoft.com/javascript/api/requirement-sets/outlook/requirement-set-1.12/office.context.mailbox.item | Object Model} page. -/// -/// If you want to see IntelliSense for only a specific type or mode, cast -/// this item to one of the following: -/// -/// - {@link Office.AppointmentCompose | AppointmentCompose} -/// -/// - {@link Office.AppointmentRead | AppointmentRead} -/// -/// - {@link Office.MessageCompose | MessageCompose} -/// -/// - {@link Office.MessageRead | MessageRead} +/// Range represents a set of one or more contiguous cells such as a cell, +/// a row, a column, or a block of cells. +/// To learn more about how ranges are used throughout the API, +/// start with {@link https://docs.microsoft.com/office/dev/add-ins/excel/excel-add-ins-core-concepts#ranges | Ranges in the Excel JavaScript API}. /// /// @remarks +/// [Api set: ExcelApi 1.1] /// -/// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/understanding-outlook-add-in-permissions | Minimum permission level}**: **restricted** -/// -/// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points | Applicable Outlook mode}**: Appointment Organizer, Appointment Attendee, Message Compose, Message Read -@JS('Item') -abstract class ItemJsImpl { - /// Gets the type of item that an instance represents. +@JS('Range') +abstract class RangeJsImpl extends office_extension_js.ClientObjectJsImpl { + /// The request context associated with the object. This connects + /// the add-in's process to the Office host application's process. */ + @override + external RequestContextJsImpl get context; + + /// Returns the used range of the given range object. + /// If there are no used cells within the range, this function + /// will throw an `ItemNotFound` error. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + /// + /// @param valuesOnly Considers only cells with values as used cells. + /// [Api set: ExcelApi 1.2] + external RangeJsImpl getUsedRange([final bool? valuesOnly]); + + /// Returns a `Range` object that represents the surrounding region + /// for the top-left cell in this range. A surrounding region is + /// a range bounded by any combination of blank rows and + /// blank columns relative to this range. + /// + /// @remarks + /// [Api set: ExcelApi 1.7] + external RangeJsImpl getSurroundingRegion(); + + + /// Gets the `Range` object beginning at a particular row index and + /// column index, and spanning a certain number of rows and columns. + /// + /// @remarks + /// [Api set: ExcelApi 1.7] + /// + /// @param startRow Start row (zero-indexed). + /// @param startColumn Start column (zero-indexed). + /// @param rowCount Number of rows to include in the range. + /// @param columnCount Number of columns to include in the range. + external RangeJsImpl getRangeByIndexes( + final int startRow, + final int startColumn, + final int rowCount, + final int columnCount, + ); + + /// Gets a row contained in the range. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + /// + /// @param row Row number of the range to be retrieved. Zero-indexed. + external RangeJsImpl getRow(final int row); + + /// Gets the last cell within the range. For example, + /// the last cell of "B2:D5" is "D5". + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external RangeJsImpl getLastCell(); + + /// Gets the last column within the range. For example, + /// the last column of "B2:D5" is "D2:D5". + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external RangeJsImpl getLastColumn(); + + /// Gets the last row within the range. For example, + /// the last row of "B2:D5" is "B5:D5". + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external RangeJsImpl getLastRow(); + + /// Gets a column contained in the range. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + /// + /// @param column Column number of the range to be retrieved. Zero-indexed. + external RangeJsImpl getColumn(final int column); + + /// Queues up a command to load the specified properties of the object. + /// You must call `context.sync()` before reading the properties. + /// + /// @param propertyNames A comma-delimited string or an array of strings + /// that specify the properties to load. + external RangeJsImpl load(final List propertyNames); + + /// Represents the raw values of the specified range. + /// The data returned could be a string, number, or boolean. + /// Cells that contain an error will return the error string. + /// + /// If the returned value starts with a plus ("+"), minus ("-"), + /// or equal sign ("="), Excel interprets this value as a formula. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external List get values; + external set values(final List values); + + /// Returns the total number of rows in the range. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external int get rowCount; + + /// Returns the row number of the first cell in the range. Zero-indexed. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external int get rowIndex; + + /// Specifies the total number of columns in the range. + /// + /// @remarks + /// [Api set: ExcelApi 1.1] + external int get columnCount; + + /// Specifies the column number of the first cell in the range. Zero-indexed. /// - /// The `itemType` property returns one of the `ItemType` - /// enumeration values, indicating whether the `item` object instance - /// is a message or an appointment. + /// @remarks + /// [Api set: ExcelApi 1.1] + external int get columnIndex; + + /// Represents Excel's number format code for the given range. /// /// @remarks + /// [Api set: ExcelApi 1.1] + external List get numberFormat; + external set numberFormat(final List value); + + /// Returns a format object, encapsulating the range's font, + /// fill, borders, alignment, and other properties. /// - /// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/understanding-outlook-add-in-permissions | Minimum permission level}**: **read item** + /// @remarks + /// [Api set: ExcelApi 1.1] + external RangeFormatJsImpl get format; + + + //new clear code + external Future clear(String v); + // Add the following method to the RangeJsImpl class + external Future delete(String shiftDirection); + + + + external Future insert(String direction); + + //new code + + +//new code end +} + +/// A format object encapsulating the range's font, fill, borders, +/// alignment, and other properties. +/// +/// @remarks +/// [Api set: ExcelApi 1.1] +@JS('RangeFormat') +abstract class RangeFormatJsImpl + extends office_extension_js.ClientObjectJsImpl { + /// The request context associated with the object. This connects + /// the add-in's process to the Office host application's process. */ + @override + external RequestContextJsImpl get context; + + /// Specifies if Excel wraps the text in the object. + /// A `null` value indicates that the entire range + /// doesn't have a uniform wrap setting /// - /// **{@link https://learn.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points | Applicable Outlook mode}**: Appointment Organizer - /// @returns [ItemType] - external String? get itemType; + /// @remarks + /// [Api set: ExcelApi 1.1] + external bool get wrapText; + external set wrapText(final bool value); + + + /* + //new code starts + + /// Specifies if text is automatically indented when text alignment is set to equal distribution. + external bool get autoIndent; + external set autoIndent(bool value); + + /// Collection of border objects that apply to the overall range. + external Excel.RangeBorderCollectionJsImpl get borders; + + /// Specifies the width of all columns within the range. If the column widths are not uniform, null will be returned. + external double get columnWidth; + external set columnWidth(double value); + + /// Returns the fill object defined on the overall range. + external Excel.RangeFillJsImpl get fill; + + /// Returns the font object defined on the overall range. + external Excel.RangeFontJsImpl get font; + + /// Represents the horizontal alignment for the specified object. + external Excel.HorizontalAlignment get horizontalAlignment; + external set horizontalAlignment(Excel.HorizontalAlignment value); + + /// An integer from 0 to 250 that indicates the indent level. + external int get indentLevel; + external set indentLevel(int value); + + /// Returns the format protection object for a range. + external Excel.FormatProtectionJsImpl get protection; + + /// The reading order for the range. + external Excel.ReadingOrder get readingOrder; + external set readingOrder(Excel.ReadingOrder value); + + /// The height of all rows in the range. If the row heights are not uniform, null will be returned. + external double get rowHeight; + external set rowHeight(double value); + + /// Specifies if text automatically shrinks to fit in the available column width. + external bool get shrinkToFit; + external set shrinkToFit(bool value); + + /// The text orientation of all the cells within the range. + external int get textOrientation; + external set textOrientation(int value); + + /// Determines if the row height of the Range object equals the standard height of the sheet. + external bool get useStandardHeight; + external set useStandardHeight(bool value); + + /// Specifies if the column width of the Range object equals the standard width of the sheet. + external bool get useStandardWidth; + external set useStandardWidth(bool value); + + /// Represents the vertical alignment for the specified object. + external Excel.VerticalAlignment get verticalAlignment; + external set verticalAlignment(Excel.VerticalAlignment value); + + external void adjustIndent(int amount); + + external void autofitColumns(); + + external void autofitRows(); + + external RangeFormatJsImpl load(Excel.Interfaces.RangeFormatLoadOptions options); + + external RangeFormatJsImpl loadProperties(List propertyNames); + + external RangeFormatJsImpl loadPropertiesAndPaths( + Excel.Interfaces.RangeFormatLoadOptions options); + + external void setProperties( + Excel.Interfaces.RangeFormatUpdateData properties, + OfficeExtension.UpdateOptions options); + + external void setFromExisting(RangeFormatJsImpl properties); + + // external Excel.Interfaces.RangeFormat toJson(); + +//new code ends +*/ + }