pub mod columns;
pub mod concerns;
pub mod config;
mod console;
pub mod coordinate;
mod error;
pub mod events;
mod excel;
mod export;
mod fake;
mod html;
mod html_writer;
mod import;
mod number_formatter;
mod other_readers;
mod provider;
mod queue;
mod reader;
mod rich_text;
mod row;
pub mod sheets;
pub mod spreadsheet;
pub mod style;
mod value;
mod writer;
mod xlsx_extras;
pub use config::{CsvExportSettings, CsvImportSettings, ExcelConfig};
pub use error::{ExcelError, Failure, ValidationException};
pub use excel::{
AsDynExport, AsDynImport, Excel, Exportable, ImportFile, Importable, PendingDownload, PendingImport, PendingQueue,
PendingQueueImport, PendingRows, PendingStore, Queued, Type,
};
pub use export::{Export, SheetWriter};
pub use fake::ExcelFake;
pub use import::{HeadingRowFormatter, Import, SheetImport, SheetRows, slug};
pub use provider::{Errors, ExcelServiceProvider, Failures, HeadingRowImport};
pub use queue::{QueuedExportJob, QueuedImportJob};
pub use row::{IntoRows, Key, Row};
pub use sheets::{SheetKey, Sheets};
pub use spreadsheet::{Chart, ChartSeries, ChartType, Comment, Drawing, Hyperlink, Spreadsheet, TextRun, Worksheet};
pub use style::{Style, number_format};
pub use value::{
AdvancedValueBinder, DefaultValueBinder, StringValueBinder, Value, ValueBinder, date_time_to_excel,
excel_to_date_time,
};
pub use xlsx_extras::ImageContent;
#[doc(hidden)]
pub mod __private {
use std::any::Any;
use std::sync::Arc;
pub use futures_util::future::BoxFuture;
pub use inventory;
pub use laravel::Result;
pub use serde_json;
#[cfg(feature = "scout")]
pub use crate::export::write_scout;
pub use crate::export::{
ExportConcerns, SheetWriter, Source, count_query, write_array, write_collection, write_generator,
write_iterator, write_query,
};
pub use crate::import::{
ImportConcerns, SheetImport, handle_array, handle_collection, handle_each_row, handle_models,
};
pub use crate::queue::{QueueableExport, QueueableImport};
pub use crate::row::into_single_row;
pub use crate::sheets::Sheet;
pub struct Snapshot<'a, T>(pub &'a T);
pub trait SnapshotClone {
fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>>;
}
impl<T: Clone + Any + Send + Sync> SnapshotClone for Snapshot<'_, T> {
fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>> {
Some(Arc::new(self.0.clone()))
}
}
pub trait SnapshotNone {
fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>>;
}
impl<T> SnapshotNone for &Snapshot<'_, T> {
fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>> {
None
}
}
}
#[doc(hidden)]
#[macro_export]
macro_rules! __if_has {
(ToModel; [ToModel $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(ToCollection; [ToCollection $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(ToArray; [ToArray $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(OnEachRow; [OnEachRow $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(WithMapping; [WithMapping $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(WithCustomQuerySize; [WithCustomQuerySize $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(ShouldQueue; [ShouldQueue $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(ShouldQueue; [Queueable $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
(ShouldQueue; [ShouldQueueWithoutChain $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
($name:ident; [$other:ident $(, $rest:ident)*] => { $($code:tt)* }) => {
$crate::__if_has! { $name; [$($rest),*] => { $($code)* } }
};
($name:ident; [] => { $($code:tt)* }) => {};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __if_has_else {
(WithMapping; [WithMapping $(, $rest:ident)*] => { $($yes:tt)* } else { $($no:tt)* }) => { $($yes)* };
(WithCustomQuerySize; [WithCustomQuerySize $(, $rest:ident)*] => { $($yes:tt)* } else { $($no:tt)* }) => { $($yes)* };
($name:ident; [$other:ident $(, $rest:ident)*] => { $($yes:tt)* } else { $($no:tt)* }) => {
$crate::__if_has_else!($name; [$($rest),*] => { $($yes)* } else { $($no)* })
};
($name:ident; [] => { $($yes:tt)* } else { $($no:tt)* }) => { $($no)* };
}
#[doc(hidden)]
#[macro_export]
macro_rules! __export_concern {
($s:tt, $c:ident, FromCollection) => {
$c.source = $crate::__private::Source::Collection;
};
($s:tt, $c:ident, FromArray) => {
$c.source = $crate::__private::Source::Array;
};
($s:tt, $c:ident, FromIterator) => {
$c.source = $crate::__private::Source::Iterator;
};
($s:tt, $c:ident, FromGenerator) => {
$c.source = $crate::__private::Source::Generator;
};
($s:tt, $c:ident, FromQuery) => {
$c.source = $crate::__private::Source::Query;
};
($s:tt, $c:ident, FromScout) => {
$c.source = $crate::__private::Source::Scout;
};
($s:tt, $c:ident, FromView) => {
$c.view = Some($s);
};
($s:tt, $c:ident, WithHeadings) => {
$c.headings = Some(::std::boxed::Box::new(move || {
$crate::IntoRows::into_rows($crate::concerns::WithHeadings::headings($s))
}));
};
($s:tt, $c:ident, WithMapping) => {
$c.mapping = true;
};
($s:tt, $c:ident, WithColumns) => {
$c.columns = Some($s);
};
($s:tt, $c:ident, WithCharts) => {
$c.charts = Some($s);
};
($s:tt, $c:ident, WithExportTemplate) => {
$c.template = Some($s);
};
($s:tt, $c:ident, WithColumnFormatting) => {
$c.column_formatting = Some($s);
};
($s:tt, $c:ident, ShouldAutoSize) => {
let _: &dyn $crate::concerns::ShouldAutoSize = $s;
$c.should_auto_size = true;
};
($s:tt, $c:ident, WithTitle) => {
$c.title = Some($s);
};
($s:tt, $c:ident, WithMultipleSheets) => {
$c.multiple_sheets = Some($s);
};
($s:tt, $c:ident, WithConditionalSheets) => {
$c.multiple_sheets = Some($s);
};
($s:tt, $c:ident, WithStyles) => {
$c.styles = Some($s);
};
($s:tt, $c:ident, WithEvents) => {
$c.events = Some($s);
};
($s:tt, $c:ident, WithCustomStartCell) => {
$c.start_cell = Some($s);
};
($s:tt, $c:ident, WithStrictNullComparison) => {
let _: &dyn $crate::concerns::WithStrictNullComparison = $s;
$c.strict_null_comparison = true;
};
($s:tt, $c:ident, HasReferencesToOtherSheets) => {
let _: &dyn $crate::concerns::HasReferencesToOtherSheets = $s;
};
($s:tt, $c:ident, WithProperties) => {
$c.properties = Some($s);
};
($s:tt, $c:ident, WithColumnWidths) => {
$c.column_widths = Some($s);
};
($s:tt, $c:ident, WithFreezePane) => {
$c.freeze_pane = Some($s);
};
($s:tt, $c:ident, WithTabColor) => {
$c.tab_color = Some($s);
};
($s:tt, $c:ident, WithSheetProtection) => {
$c.sheet_protection = Some($s);
};
($s:tt, $c:ident, WithPageBreaks) => {
$c.page_breaks = Some($s);
};
($s:tt, $c:ident, WithPrintArea) => {
$c.print_area = Some($s);
};
($s:tt, $c:ident, WithDrawings) => {
$c.drawings = Some($s);
};
($s:tt, $c:ident, WithDefaultStyles) => {
$c.default_styles = Some($s);
};
($s:tt, $c:ident, WithBackgroundColor) => {
$c.background_color = Some($s);
};
($s:tt, $c:ident, WithCustomValueBinder) => {
let _: &dyn $crate::concerns::WithCustomValueBinder = $s;
$c.value_binder = Some($s);
};
($s:tt, $c:ident, WithCustomCsvSettings) => {
$c.csv_settings = Some($s);
};
($s:tt, $c:ident, WithCustomChunkSize) => {
$c.chunk_size = Some($s);
};
($s:tt, $c:ident, WithCustomQuerySize) => {};
($s:tt, $c:ident, WithPreCalculateFormulas) => {
let _: &dyn $crate::concerns::WithPreCalculateFormulas = $s;
$c.pre_calculate_formulas = true;
};
($s:tt, $c:ident, ShouldQueue) => {
$c.should_queue = Some($s);
};
($s:tt, $c:ident, ShouldBatch) => {
let _: &dyn $crate::concerns::ShouldBatch = $s;
$c.should_batch = true;
};
($s:tt, $c:ident, Queueable) => {};
($s:tt, $c:ident, $other:ident) => {
::core::compile_error!(::core::concat!(
"`",
::core::stringify!($other),
"` isn't an export concern laravel-excel supports"
));
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __export_source {
($s:tt, $sheet:ident, $window:ident, [FromCollection $(, $rest:ident)*], $all:tt) => {
$crate::__private::write_collection($s, $sheet, $crate::__export_mapper!($s, $all)).await
};
($s:tt, $sheet:ident, $window:ident, [FromArray $(, $rest:ident)*], $all:tt) => {
$crate::__private::write_array($s, $sheet, $crate::__export_mapper!($s, $all)).await
};
($s:tt, $sheet:ident, $window:ident, [FromIterator $(, $rest:ident)*], $all:tt) => {
$crate::__private::write_iterator($s, $sheet, $crate::__export_mapper!($s, $all)).await
};
($s:tt, $sheet:ident, $window:ident, [FromGenerator $(, $rest:ident)*], $all:tt) => {
$crate::__private::write_generator($s, $sheet, $crate::__export_mapper!($s, $all)).await
};
($s:tt, $sheet:ident, $window:ident, [FromQuery $(, $rest:ident)*], $all:tt) => {
$crate::__private::write_query($s, $sheet, $window, $crate::__export_mapper!($s, $all)).await
};
($s:tt, $sheet:ident, $window:ident, [FromScout $(, $rest:ident)*], $all:tt) => {
$crate::__private::write_scout($s, $sheet, $crate::__export_mapper!($s, $all)).await
};
($s:tt, $sheet:ident, $window:ident, [$other:ident $(, $rest:ident)*], $all:tt) => {
$crate::__export_source!($s, $sheet, $window, [$($rest),*], $all)
};
($s:tt, $sheet:ident, $window:ident, [], $all:tt) => {
::core::result::Result::Ok(())
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __export_mapper {
($s:tt, [$($all:ident),*]) => {
$crate::__if_has_else!(WithMapping; [$($all),*] => {
|row| $crate::concerns::WithMapping::map($s, row)
} else {
|row| row
})
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __export_count {
($s:tt, [FromQuery $(, $rest:ident)*], [$($all:ident),*]) => {
$crate::__if_has_else!(WithCustomQuerySize; [$($all),*] => {
::core::result::Result::Ok(::core::option::Option::Some(
$crate::concerns::WithCustomQuerySize::query_size($s).await?,
))
} else {
::core::result::Result::Ok(::core::option::Option::Some($crate::__private::count_query($s).await?))
})
};
($s:tt, [$other:ident $(, $rest:ident)*], $all:tt) => {
$crate::__export_count!($s, [$($rest),*], $all)
};
($s:tt, [], $all:tt) => {
::core::result::Result::Ok(::core::option::Option::None)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __snapshot_and_name {
($ty:ty) => {
fn __type_name(&self) -> &'static str {
::core::any::type_name::<$ty>()
}
fn __snapshot(
&self,
) -> ::core::option::Option<::std::sync::Arc<dyn ::core::any::Any + ::core::marker::Send + ::core::marker::Sync>> {
#[allow(unused_imports)]
use $crate::__private::{SnapshotClone as _, SnapshotNone as _};
(&$crate::__private::Snapshot(self)).__snapshot()
}
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __queue_payload {
($ty:ty; $all:tt) => {
$crate::__if_has! { ShouldQueue; $all => {
fn __queue_payload(
&self,
) -> ::core::option::Option<$crate::__private::Result<(&'static str, $crate::__private::serde_json::Value)>> {
::core::option::Option::Some(
$crate::__private::serde_json::to_value(self)
.map(|value| (::core::concat!(::core::module_path!(), "::", ::core::stringify!($ty)), value))
.map_err(::core::convert::Into::into),
)
}
} }
};
}
#[macro_export]
macro_rules! export {
($ty:ty : $($concern:ident),* $(,)?) => {
impl $crate::Export for $ty {
fn __concerns(&self) -> $crate::__private::ExportConcerns<'_> {
#[allow(unused_mut)]
let mut concerns = $crate::__private::ExportConcerns::default();
$( $crate::__export_concern!(self, concerns, $concern); )*
concerns
}
fn __write<'a>(
&'a self,
sheet: &'a mut $crate::__private::SheetWriter<'_>,
window: ::core::option::Option<(u64, u64)>,
) -> $crate::__private::BoxFuture<'a, $crate::__private::Result<()>> {
::std::boxed::Box::pin(async move {
let _ = (&sheet, &window);
$crate::__export_source!(self, sheet, window, [$($concern),*], [$($concern),*])
})
}
fn __count(&self) -> $crate::__private::BoxFuture<'_, $crate::__private::Result<::core::option::Option<u64>>> {
::std::boxed::Box::pin(async move {
$crate::__export_count!(self, [$($concern),*], [$($concern),*])
})
}
$crate::__snapshot_and_name!($ty);
$crate::__queue_payload!($ty; [$($concern),*]);
}
impl $crate::sheets::IntoSheet for $ty {
fn into_sheet(self) -> $crate::__private::Sheet {
$crate::__private::Sheet::Export(::std::boxed::Box::new(self))
}
}
$crate::__if_has! { ShouldQueue; [$($concern),*] => {
$crate::__private::inventory::submit! {
$crate::__private::QueueableExport {
name: ::core::concat!(::core::module_path!(), "::", ::core::stringify!($ty)),
restore: {
fn restore(
value: $crate::__private::serde_json::Value,
) -> $crate::__private::Result<::std::boxed::Box<dyn $crate::Export>> {
::core::result::Result::Ok(::std::boxed::Box::new(
$crate::__private::serde_json::from_value::<$ty>(value)?,
))
}
restore
},
}
}
} }
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __import_concern {
($s:tt, $c:ident, ToModel) => {};
($s:tt, $c:ident, ToCollection) => {};
($s:tt, $c:ident, ToArray) => {};
($s:tt, $c:ident, OnEachRow) => {};
($s:tt, $c:ident, WithHeadingRow) => {
$c.heading_row = Some($s);
};
($s:tt, $c:ident, WithGroupedHeadingRow) => {
let _: &dyn $crate::concerns::WithGroupedHeadingRow = $s;
$c.heading_row = Some($s);
$c.grouped_heading_row = true;
};
($s:tt, $c:ident, WithStartRow) => {
$c.start_row = Some($s);
};
($s:tt, $c:ident, WithLimit) => {
$c.limit = Some($s);
};
($s:tt, $c:ident, WithColumnLimit) => {
$c.column_limit = Some($s);
};
($s:tt, $c:ident, WithMappedCells) => {
$c.mapped_cells = Some($s);
};
($s:tt, $c:ident, WithMapping) => {
$c.mapping = Some(::std::boxed::Box::new(move |row: $crate::Row| {
$crate::__private::into_single_row(<Self as $crate::concerns::WithMapping<$crate::Row>>::map($s, row))
}));
};
($s:tt, $c:ident, WithValidation) => {
$c.validation = Some($s);
};
($s:tt, $c:ident, SkipsOnFailure) => {
$c.skips_on_failure = Some($s);
};
($s:tt, $c:ident, SkipsOnError) => {
$c.skips_on_error = Some($s);
};
($s:tt, $c:ident, SkipsEmptyRows) => {
$c.skips_empty_rows = Some($s);
};
($s:tt, $c:ident, SkipsUnknownSheets) => {
$c.skips_unknown_sheets = Some($s);
};
($s:tt, $c:ident, WithCalculatedFormulas) => {
let _: &dyn $crate::concerns::WithCalculatedFormulas = $s;
$c.calculated_formulas = true;
};
($s:tt, $c:ident, WithColumns) => {
$c.columns = Some($s);
};
($s:tt, $c:ident, WithFormatData) => {
let _: &dyn $crate::concerns::WithFormatData = $s;
$c.format_data = true;
};
($s:tt, $c:ident, WithSkipDuplicates) => {
let _: &dyn $crate::concerns::WithSkipDuplicates = $s;
$c.skip_duplicates = true;
};
($s:tt, $c:ident, WithReadFilter) => {
$c.read_filter = Some($s);
};
($s:tt, $c:ident, WithProgressBar) => {
$c.progress_bar = Some($s);
};
($s:tt, $c:ident, WithStrictNullComparison) => {
let _: &dyn $crate::concerns::WithStrictNullComparison = $s;
$c.strict_null_comparison = true;
};
($s:tt, $c:ident, WithEvents) => {
$c.events = Some($s);
};
($s:tt, $c:ident, WithCustomCsvSettings) => {
$c.csv_settings = Some($s);
};
($s:tt, $c:ident, WithCustomValueBinder) => {
let _: &dyn $crate::concerns::WithCustomValueBinder = $s;
$c.value_binder = Some($s);
};
($s:tt, $c:ident, WithMultipleSheets) => {
$c.multiple_sheets = Some($s);
};
($s:tt, $c:ident, WithConditionalSheets) => {
$c.multiple_sheets = Some($s);
};
($s:tt, $c:ident, WithBatchInserts) => {
$c.batch_inserts = Some($s);
};
($s:tt, $c:ident, WithChunkReading) => {
$c.chunk_reading = Some($s);
};
($s:tt, $c:ident, WithUpserts) => {
$c.upserts = Some($s);
};
($s:tt, $c:ident, WithUpsertColumns) => {
$c.upsert_columns = Some($s);
};
($s:tt, $c:ident, ShouldQueue) => {
$c.should_queue = Some($s);
};
($s:tt, $c:ident, ShouldBatch) => {
let _: &dyn $crate::concerns::ShouldBatch = $s;
$c.should_batch = true;
};
($s:tt, $c:ident, ShouldQueueWithoutChain) => {
$c.should_queue = Some($s);
$c.without_chain = Some($s);
};
($s:tt, $c:ident, RemembersRowNumber) => {
let _: &dyn $crate::concerns::RemembersRowNumber = $s;
};
($s:tt, $c:ident, RemembersChunkOffset) => {
let _: &dyn $crate::concerns::RemembersChunkOffset = $s;
};
($s:tt, $c:ident, Queueable) => {};
($s:tt, $c:ident, $other:ident) => {
::core::compile_error!(::core::concat!(
"`",
::core::stringify!($other),
"` isn't an import concern laravel-excel supports"
));
};
}
#[macro_export]
macro_rules! import {
($ty:ty : $($concern:ident),* $(,)?) => {
impl $crate::Import for $ty {
fn __concerns(&self) -> $crate::__private::ImportConcerns<'_> {
#[allow(unused_mut)]
let mut concerns = $crate::__private::ImportConcerns::default();
$( $crate::__import_concern!(self, concerns, $concern); )*
concerns
}
fn __handle<'a>(
&'a self,
sheet: &'a $crate::__private::SheetImport<'a>,
) -> $crate::__private::BoxFuture<'a, $crate::__private::Result<()>> {
::std::boxed::Box::pin(async move {
let _ = &sheet;
$crate::__if_has!(ToModel; [$($concern),*] => {
$crate::__private::handle_models(self, sheet).await?;
});
$crate::__if_has!(ToCollection; [$($concern),*] => {
$crate::__private::handle_collection(self, sheet).await?;
});
$crate::__if_has!(ToArray; [$($concern),*] => {
$crate::__private::handle_array(self, sheet).await?;
});
$crate::__if_has!(OnEachRow; [$($concern),*] => {
$crate::__private::handle_each_row(self, sheet).await?;
});
::core::result::Result::Ok(())
})
}
$crate::__snapshot_and_name!($ty);
$crate::__queue_payload!($ty; [$($concern),*]);
}
impl $crate::sheets::IntoSheet for $ty {
fn into_sheet(self) -> $crate::__private::Sheet {
$crate::__private::Sheet::Import(::std::boxed::Box::new(self))
}
}
$crate::__if_has! { ShouldQueue; [$($concern),*] => {
$crate::__private::inventory::submit! {
$crate::__private::QueueableImport {
name: ::core::concat!(::core::module_path!(), "::", ::core::stringify!($ty)),
restore: {
fn restore(
value: $crate::__private::serde_json::Value,
) -> $crate::__private::Result<::std::boxed::Box<dyn $crate::Import>> {
::core::result::Result::Ok(::std::boxed::Box::new(
$crate::__private::serde_json::from_value::<$ty>(value)?,
))
}
restore
},
}
}
} }
};
}