Save file name in excel file.

This commit is contained in:
aj
2018-06-10 19:05:05 -04:00
parent a578af87a3
commit bc2ac5b782
3 changed files with 49 additions and 27 deletions

View File

@@ -313,10 +313,8 @@ namespace ExportDXF.Forms
if (worker.CancellationPending)
break;
item.ItemNo = prefix + item.ItemNo;
var fileName = item.ItemNo + ".dxf";
var savepath = Path.Combine(savePath, fileName);
var fileName = GetFileName(item);
var savepath = Path.Combine(savePath, fileName + ".dxf");
var model = item.Component.GetModelDoc2() as ModelDoc2;
var part = model as PartDoc;
@@ -351,7 +349,11 @@ namespace ExportDXF.Forms
if (part == null)
continue;
SavePartToDXF(part, config, savepath);
if (SavePartToDXF(part, config, savepath))
{
item.FileName = Path.GetFileNameWithoutExtension(savepath);
}
Application.DoEvents();
}
@@ -368,6 +370,20 @@ namespace ExportDXF.Forms
}
}
private string GetFileName(Item item)
{
var prefix = prefixTextBox.Text.Replace("\"", "''");
if (string.IsNullOrWhiteSpace(item.ItemNo))
{
return prefix + item.PartName;
}
else
{
return prefix + item.ItemNo.PadLeft(2, '0');
}
}
private string ChangePathExtension(string fullpath, string newExtension)
{
var dir = Path.GetDirectoryName(fullpath);
@@ -451,25 +467,30 @@ namespace ExportDXF.Forms
{
var item = items[i];
var row = i + 2;
var col = 1;
partsSheet.Cells[row, 1].Value = item.ItemNo;
partsSheet.Cells[row, 2].Value = item.Quantity;
partsSheet.Cells[row, 3].Value = item.Description;
partsSheet.Cells[row, 4].Value = item.PartNo;
partsSheet.Cells[row, col++].Value = item.ItemNo;
partsSheet.Cells[row, col++].Value = item.FileName;
partsSheet.Cells[row, col++].Value = item.Quantity;
partsSheet.Cells[row, col++].Value = item.Description;
partsSheet.Cells[row, col++].Value = item.PartName;
if (item.Thickness > 0)
partsSheet.Cells[row, 5].Value = item.Thickness;
partsSheet.Cells[row, col].Value = item.Thickness;
col++;
partsSheet.Cells[row, 6].Value = item.Material;
partsSheet.Cells[row, col++].Value = item.Material;
if (item.KFactor > 0)
partsSheet.Cells[row, 7].Value = item.KFactor;
partsSheet.Cells[row, col].Value = item.KFactor;
col++;
if (item.BendRadius > 0)
partsSheet.Cells[row, 8].Value = item.BendRadius;
partsSheet.Cells[row, col].Value = item.BendRadius;
col++;
}
partsSheet.Column(1).AutoFit();
partsSheet.Column(2).AutoFit();
workbook.Calculate();
pkg.Save();
@@ -583,10 +604,10 @@ namespace ExportDXF.Forms
{
items.Add(new Item
{
PartNo = table.DisplayedText[rowIndex, partNoColumnIndex],
PartName = table.DisplayedText[rowIndex, partNoColumnIndex],
Quantity = int.Parse(table.DisplayedText[rowIndex, qtyColumnIndex]),
Description = table.DisplayedText[rowIndex, descriptionColumnIndex],
ItemNo = table.DisplayedText[rowIndex, itemNoColumnIndex].PadLeft(2, '0'),
ItemNo = table.DisplayedText[rowIndex, itemNoColumnIndex],
Component = distinctComponents.First()
});
}
@@ -623,8 +644,7 @@ namespace ExportDXF.Forms
list.Add(new Item
{
ItemNo = name,
PartNo = name,
PartName = name,
Quantity = group.Count(),
Component = component
});

View File

@@ -2,24 +2,26 @@
namespace ExportDXF
{
public class Item
public class Item
{
public string ItemNo { get; set; }
public string ItemNo { get; set; }
public string PartNo { get; set; }
public string FileName { get; set; }
public string PartName { get; set; }
public int Quantity { get; set; }
public string Description { get; set; }
public string Description { get; set; }
public double Thickness { get; set; }
public double Thickness { get; set; }
public double KFactor { get; set; }
public double KFactor { get; set; }
public double BendRadius { get; set; }
public double BendRadius { get; set; }
public string Material { get; set; }
public string Material { get; set; }
public Component2 Component { get; set; }
public Component2 Component { get; set; }
}
}

Binary file not shown.