spreadcheetah icon indicating copy to clipboard operation
spreadcheetah copied to clipboard

Source generator - Fixed column widths

Open sveinungf opened this issue 3 months ago • 0 comments

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);

sveinungf avatar Apr 06 '24 11:04 sveinungf