У меня есть книга Excel с 27 различными листами, 24 из них заполнены только из 3 из них, и я пытаюсь вставить необходимые данные в 3 листа.
Проблема, с которой я сталкиваюсь, заключается в том, что на двух рабочих листах (HeaderExport и MarkupExport) данные вставляются чуть ниже строки, где это необходимо, и все другие рабочие листы не могут их прочитать. Как я могу вставить данные, начиная с правильной строки?
Также на третьем листе (EstimateExportData) я не могу получить какие-либо данные для вставки в любое место на листе. Я дважды проверил написание имени листа и его правильность. Я пробовал это со строкой и числом, в Excel столбец является общим. Не выдается никаких ошибок
Любая помощь будет принята с благодарностью, спасибо
private void radExportToPivot_Click(object sender, EventArgs e)
{
//where the excel template file is stored
string sourcePath = @"C:\TEMP\METExport.xlsx";
string targetPath;
//ask the user where they want to save it to
RadSaveFileDialog saveFileDialog = new RadSaveFileDialog();
DialogResult dr = saveFileDialog.ShowDialog();
if (dr == DialogResult.OK)
{
targetPath = saveFileDialog.FileName;
}
else
{
return;
}
if (!targetPath.EndsWith(".xlsx"))
{
targetPath = targetPath + ".xlsx";
}
;
//copy the file where the user said
System.IO.File.Copy(sourcePath, targetPath, true);
//set connection string
string connectionString = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source={0};Extended Properties='Excel 12.0;HDR=YES;IMEX=0'", targetPath);
//populate file with all necessary data
using (OleDbConnection cn = new OleDbConnection(connectionString))
{
cn.Open();
HeaderExport(cn);
EstimateExport(cn);
MarkUpExport(cn);
cn.Close();
}
}
private void MarkUpExport(OleDbConnection cn)
{
_entity.EstimateOverheads.Where(x => x.EstID == Est.EstID).Load();
var estOverHeads = _entity.EstimateOverheads.Local.ToBindingList();
_entity.Estimates.Where(x=>x.EstID == Est.EstID).Load();
var estimate = _entity.Estimates.Local.ToBindingList().First();
foreach (var overhead in estOverHeads)
{
OleDbCommand cmd = new OleDbCommand(
"INSERT INTO [MarkUpExport$]" +
"(LineItemType, FeeName, funding, Profit, Contingency, CommAdder, " +
"HomeField, ga, LaborBurden, OfficeOverhead, FieldOverhead, SubAdmin)" +
"VALUES(@LineItemType, @FeeName, @funding, @Profit, @Contingency, @CommAdder, " +
"@HomeField, @ga, @LaborBurden, @OfficeOverhead, @FieldOverhead, @SubAdmin)", cn);
cmd.Parameters.AddWithValue("@LineItemType", overhead.LineItemType.ToString());
cmd.Parameters.AddWithValue("@FeeName", overhead.FeeName);
cmd.Parameters.AddWithValue("@funding", estimate.funding);
cmd.Parameters.AddWithValue("@Profit", overhead.Profit);
cmd.Parameters.AddWithValue("@Contingency", overhead.Contingency);
cmd.Parameters.AddWithValue("@CommAdder", overhead.CommAdder);
cmd.Parameters.AddWithValue("@HomeField", overhead.HomeField);
cmd.Parameters.AddWithValue("@ga", overhead.ga);
cmd.Parameters.AddWithValue("@LaborBurden", overhead.LaborBurden);
cmd.Parameters.AddWithValue("@OfficeOverhead", overhead.OfficeOverhead);
cmd.Parameters.AddWithValue("@FieldOverhead", overhead.FieldOverhead);
cmd.Parameters.AddWithValue("@SubAdmin", overhead.SubAdmin);
cmd.ExecuteNonQuery();
}
}
private void EstimateExport(OleDbConnection cn)
{
OleDbCommand cmd = new OleDbCommand(
"INSERT INTO [EstimateExportData$]" +
"(RevenueType)" +
"VALUES(@RevenueType)", cn);
cmd.Parameters.AddWithValue("@RevenueType", 1);
cmd.ExecuteNonQuery();
}
private void HeaderExport(OleDbConnection cn)
{
Data.Estimate estimate = LoadDataforExport();
OleDbCommand cmd1 = new OleDbCommand(
"INSERT INTO [HeaderExport$] " +
"(Project, SubEstimate, Description, funding, MarketSector, " +
"ProjectManager, ProjectSpecialist, ClientCode, ClientClass, " +
//"Currency, " +
"ClientName, ContractNumber, StartDate" +
", FinishDate, Merrick_is_Sub, MarketSegment, ServiceBusinessUnit, ServiceLine, " +
"WorkLocation, DamagesProtection, InternationalCode, ContractForm, LEEDLevel, OrigDate, AcctManager," +
" FeeType, process_step, ContractValue, tm_comp, Company, Organization, BudgetLevel, " +
"ChargeableProject, ClientAddress, ClientCity, ClientState, ClientZip, ClientCountry, ClientContact," +
" ClientPhone, ClientFax, ClientEmail, APContact, APPhone, APFax, APEmail, ClientContractNumber, " +
"EndClient, OverallFee, WorkType, CompanyRole, WorkCity, WorkState, WorkCountry, WorkZip, " +
"Opportunity, NAICS, CertCurrentCost, LimitLiability, GHVTTax, GrossReceiptsTax, CAS, " +
"IncurredCostFAR, GSAContract, " +
"SBAPlan, " +
"DateCreated, " +
"CreatedBy, DateModified, ModifiedBy, Location, PayrollDate, RateSheet" +
") " +
"VALUES(" +
"@Project, @SubEstimate, @Description, @funding, @MarketSector, " +
"@ProjectManager, @ProjectSpecialist, @ClientCode, @ClientClass, " +
//"@Currency, " +
"@ClientName, @ContractNumber, @StartDate" +
", @FinishDate, @Merrick_is_Sub, @MarketSegment, @ServiceBusinessUnit, @ServiceLine, " +
"@WorkLocation, @DamagesProtection, @InternationalCode, @ContractForm, @LEEDLevel, @OrigDate, @AcctManager," +
" @FeeTyp, @process_stepe, @ContractValue, @tm_comp, @Company, @Organization, @BudgetLevel, " +
"@ChargeableProject, @ClientAddress, @ClientCity, @ClientState, @ClientZip, @ClientCountry, @ClientContact," +
" @ClientPhone, @ClientFax, @ClientEmail, @APContact, @APPhone, @APFax, @APEmail, @ClientContractNumber, " +
"@EndClient, @OverallFee, @WorkType, @CompanyRole, @WorkCity, @WorkState, @WorkCountry, @WorkZip, " +
"@Opportunity, @NAICS, @CertCurrentCost, @LimitLiability, @GHVTTax, @GrossReceiptsTax, @CAS, " +
"@IncurredCostFAR, @GSAContract, " +
"@SBAPlan, " +
"@DateCreated," +
"@CreatedBy, @DateModified, @ModifiedBy, @Location, @PayrollDate, @RateSheet" +
")", cn);
cmd1.Parameters.AddWithValue("@Project", estimate.Project ?? "");
cmd1.Parameters.AddWithValue("@SubEstimate", estimate.SubEstimate ?? "");
cmd1.Parameters.AddWithValue("@Description", estimate.Description ?? "");
cmd1.Parameters.AddWithValue("@funding", estimate.funding ?? "");
cmd1.Parameters.AddWithValue("@MarketSector", estimate.MarketSector ?? "");
cmd1.Parameters.AddWithValue("@ProjectManager", estimate.ProjectManager ?? "");
cmd1.Parameters.AddWithValue("@ProjectSpecialist", estimate.ProjectSpecialist ?? "");
cmd1.Parameters.AddWithValue("@ClientCode", estimate.ClientCode ?? "");
cmd1.Parameters.AddWithValue("@ClientClass", estimate.ClientClass ?? "");
//cmd1.Parameters.AddWithValue("@Currency", estimate.Currency ?? "");
cmd1.Parameters.AddWithValue("@ClientName", estimate.ClientName ?? "");
cmd1.Parameters.AddWithValue("@ContractNumber", estimate.ContractNumber ?? "");
cmd1.Parameters.AddWithValue("@StartDate", estimate.StartDate ?? DateTime.MinValue);
cmd1.Parameters.AddWithValue("@FinishDate", estimate.FinishDate ?? DateTime.MinValue);
cmd1.Parameters.AddWithValue("@Merrick_is_Sub", estimate.Merrick_is_Sub.ToString() ?? "");
cmd1.Parameters.AddWithValue("@MarketSegment", estimate.MarketSegment ?? "");
cmd1.Parameters.AddWithValue("@ServiceBusinessUnit", estimate.ServiceBusinessUnit ?? "");
cmd1.Parameters.AddWithValue("@ServiceLine", estimate.ServiceLine ?? "");
cmd1.Parameters.AddWithValue("@WorkLocation", estimate.WorkLocation ?? "");
cmd1.Parameters.AddWithValue("@DamagesProtection", estimate.DamagesProtection ?? "");
cmd1.Parameters.AddWithValue("@InternationalCode", estimate.InternationalCode ?? "");
cmd1.Parameters.AddWithValue("@ContractForm", estimate.ContractForm ?? "");
cmd1.Parameters.AddWithValue("@LEEDLevel", estimate.LEEDLevel ?? "");
cmd1.Parameters.AddWithValue("@OrigDate", estimate.OrigDate ?? DateTime.MinValue);
cmd1.Parameters.AddWithValue("@AcctManager", estimate.AcctManager ?? "");
cmd1.Parameters.AddWithValue("@FeeType", estimate.FeeType ?? "");
cmd1.Parameters.AddWithValue("@process_step", estimate.process_step.ToString() ?? "");
cmd1.Parameters.AddWithValue("@ContractValue", estimate.ContractValue.ToString() ?? "");
cmd1.Parameters.AddWithValue("@tm_comp", estimate.tm_comp.ToString() ?? "");
cmd1.Parameters.AddWithValue("@Company", estimate.Company ?? "");
cmd1.Parameters.AddWithValue("@Organization", estimate.Organization ?? "");
cmd1.Parameters.AddWithValue("@BudgetLevel", estimate.BudgetLevel ?? "");
cmd1.Parameters.AddWithValue("@ChargeableProject", estimate.ChargeableProject.ToString() ?? "");
cmd1.Parameters.AddWithValue("@ClientAddress", estimate.ClientAddress ?? "");
cmd1.Parameters.AddWithValue("@ClientCity", estimate.ClientCity ?? "");
cmd1.Parameters.AddWithValue("@ClientState", estimate.ClientState ?? "");
cmd1.Parameters.AddWithValue("@ClientZip", estimate.ClientZip ?? "");
cmd1.Parameters.AddWithValue("@ClientCountry", estimate.ClientCountry ?? "");
cmd1.Parameters.AddWithValue("@ClientContact", estimate.ClientContact ?? "");
cmd1.Parameters.AddWithValue("@ClientPhone", estimate.ClientPhone ?? "");
cmd1.Parameters.AddWithValue("@ClientFax", estimate.ClientFax ?? "");
cmd1.Parameters.AddWithValue("@ClientEmail", estimate.ClientEmail ?? "");
cmd1.Parameters.AddWithValue("@APContact", estimate.APContact ?? "");
cmd1.Parameters.AddWithValue("@APPhone", estimate.APPhone ?? "");
cmd1.Parameters.AddWithValue("@APFax", estimate.APFax ?? "");
cmd1.Parameters.AddWithValue("@APEmail", estimate.APEmail ?? "");
cmd1.Parameters.AddWithValue("@ClientContractNumber", estimate.ClientContractNumber ?? "");
cmd1.Parameters.AddWithValue("@EndClient", estimate.EndClient ?? "");
cmd1.Parameters.AddWithValue("@OverallFee", estimate.OverallFee ?? "");
cmd1.Parameters.AddWithValue("@WorkType", estimate.WorkType ?? "");
cmd1.Parameters.AddWithValue("@CompanyRole", estimate.CompanyRole ?? "");
cmd1.Parameters.AddWithValue("@WorkCity", estimate.WorkCity ?? "");
cmd1.Parameters.AddWithValue("@WorkState", estimate.WorkState ?? "");
cmd1.Parameters.AddWithValue("@WorkCountry", estimate.WorkCountry ?? "");
cmd1.Parameters.AddWithValue("@WorkZip", estimate.WorkZip ?? "");
cmd1.Parameters.AddWithValue("@Opportunity", estimate.Opportunity ?? "");
cmd1.Parameters.AddWithValue("@NAICS", estimate.NAICS ?? "");
cmd1.Parameters.AddWithValue("@CertCurrentCost", estimate.CertCurrentCost ?? "");
cmd1.Parameters.AddWithValue("@LimitLiability", estimate.LimitLiability ?? "");
cmd1.Parameters.AddWithValue("@GHVTTax", estimate.GHVTTax ?? "");
cmd1.Parameters.AddWithValue("@GrossReceiptsTax", estimate.GrossReceiptsTax ?? "");
cmd1.Parameters.AddWithValue("@CAS", estimate.CAS ?? "");
cmd1.Parameters.AddWithValue("@IncurredCostFAR", estimate.IncurredCostFAR ?? "");
cmd1.Parameters.AddWithValue("@GSAContract", estimate.GSAContract ?? "");
cmd1.Parameters.AddWithValue("@SBAPlan", estimate.SBAPlan ?? "");
cmd1.Parameters.AddWithValue("@DateCreated", estimate.DateCreated ?? DateTime.MinValue);
cmd1.Parameters.AddWithValue("@CreatedBy", estimate.CreatedBy);
cmd1.Parameters.AddWithValue("@DateModified", estimate.DateModified ?? DateTime.MinValue);
cmd1.Parameters.AddWithValue("@ModifiedBy", estimate.ModifiedBy);
cmd1.Parameters.AddWithValue("@Location", estimate.Location);
cmd1.Parameters.AddWithValue("@PayrollDate", estimate.PayrollDate ?? DateTime.MinValue);
cmd1.Parameters.AddWithValue("@RateSheet", estimate.CurrencyRate.ToString());
cmd1.ExecuteNonQuery();
}