Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source generator - Fixed column widths #45

Closed
sveinungf opened this issue Apr 6, 2024 · 1 comment
Closed

Source generator - Fixed column widths #45

sveinungf opened this issue Apr 6, 2024 · 1 comment
Milestone

Comments

@sveinungf
Copy link
Owner

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
Copy link
Owner Author

This has been implemented in version 1.16.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant