更新依赖和增强文件选择功能

在 `ExcelHelper.csproj` 中,将 `MiniExcel` 包版本从 `1.34.2` 升级到 `1.38.0`,并移除 `PolySharp` 包。
在 `ImportExcelPage.xaml` 中添加文件选择按钮,并设置相关属性。
在 `ImportExcelPage.xaml.cs` 中新增 `Button_Click` 方法以处理文件选择,及 `Grid_DragOver` 方法以支持拖拽文件功能。
This commit is contained in:
lihanbo 2025-02-28 17:03:21 +08:00
parent 8f42b5e5a7
commit b85080c2ce
3 changed files with 51 additions and 8 deletions

View File

@ -59,14 +59,9 @@
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.3.0-preview.1.25114.11" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3116-prerelease" />
<PackageReference Include="MiniExcel">
<Version>1.34.2</Version>
<Version>1.38.0</Version>
</PackageReference>
<PackageReference Include="Neo.Markdig.Xaml" Version="1.0.10" />
<PackageReference Include="PolySharp">
<Version>1.14.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SQLite" Version="3.13.0" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.171-preview01" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />

View File

@ -26,7 +26,12 @@
FontSize="20"
Foreground="White"
Text="拖拽Excel文件(.xls)到此处放开" />
<Button
Margin="0,0,0,20"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
Click="Button_Click"
Content="选择文件" />
</Grid>
</DataTemplate>
<DataTemplate x:Key="LoadingMask">
@ -46,6 +51,7 @@
AllowDrop="True"
DragEnter="Grid_DragEnter"
DragLeave="Grid_DragLeave"
DragOver="Grid_DragOver"
Drop="Grid_Drop">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="200" />

View File

@ -74,5 +74,47 @@ public partial class ImportExcelPage : Page, IView, IRecipient<UpdateDataGridCol
}
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
// 选择一个Excel文件
// 创建打开文件对话框
var openFileDialog = new Microsoft.Win32.OpenFileDialog
{
Filter = "Excel文件|*.xlsx;*.xls",
Title = "选择Excel文件"
};
// 显示对话框
if (openFileDialog.ShowDialog() == true)
{
// 获取选择的文件路径
var filePath = openFileDialog.FileName;
// 调用ViewModel的方法处理文件
ViewModel.FileDrop(new string[] { filePath });
DropFileMask.Visibility = System.Windows.Visibility.Collapsed;
}
}
/// <summary>
/// 处理拖拽悬停事件
/// </summary>
private void Grid_DragOver(object sender, System.Windows.DragEventArgs e)
{
// 如果拖入的是文件
if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
{
// 设置效果为复制,表示接受拖放
e.Effects = System.Windows.DragDropEffects.Copy;
}
else
{
// 不接受非文件拖放
e.Effects = System.Windows.DragDropEffects.None;
}
// 标记事件已处理,防止冒泡
e.Handled = true;
}
}