spreadcheetah
spreadcheetah copied to clipboard
Source generator - Fixed column widths
Background and motivation
Fixed column widths are now set on WorksheetOptions
when creating a worksheet. There is a desire to be able to set these with attributes instead when using the source generator. A fairly straight forward way to then have them applied to a worksheet would be to pass the source generator metadata type to StartWorksheetAsync
.
API proposal
namespace SpreadCheetah.SourceGeneration;
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public sealed class ColumnWidthAttribute(double width) : Attribute;
namespace SpreadCheetah;
public sealed class Spreadsheet
{
public ValueTask StartWorksheetAsync<T>(string name, WorksheetRowTypeInfo<T> typeInfo, CancellationToken token = default);
}
API usage
public class Person
{
[ColumnWidth(20)]
public string FirstName { get; set; }
}
[WorksheetRow(typeof(Person))]
public partial class PersonRowContext : WorksheetRowContext;
await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream);
await spreadsheet.StartWorksheetAsync("Sheet 1", PersonRowContext.Default.Person);